@graphql-tools/executor-http
Advanced tools
Comparing version 1.2.0-alpha-359d0599774929421e75780a3742aab822798dd2 to 1.2.0-alpha-52e7c9192bd3022251be5c3cabe546398300b30d
# @graphql-tools/executor-http | ||
## 1.2.0-alpha-359d0599774929421e75780a3742aab822798dd2 | ||
## 1.2.0-alpha-52e7c9192bd3022251be5c3cabe546398300b30d | ||
### Minor Changes | ||
- [#313](https://github.com/graphql-hive/gateway/pull/313) [`9f40491`](https://github.com/graphql-hive/gateway/commit/9f404916e31495526e7ca3df476e884ff986d6ff) Thanks [@ardatan](https://github.com/ardatan)! - Automatic Persisted Queries support for upstream requests | ||
- [#313](https://github.com/graphql-hive/gateway/pull/313) [`e994596`](https://github.com/graphql-hive/gateway/commit/e9945962de597d7547bbca174bdcc63f2c98260d) Thanks [@ardatan](https://github.com/ardatan)! - Automatic Persisted Queries support for upstream requests | ||
@@ -9,0 +9,0 @@ For HTTP Executor; |
@@ -83,2 +83,8 @@ import { ExecutionRequest, DisposableSyncExecutor, DisposableAsyncExecutor } from '@graphql-tools/utils'; | ||
} | ||
type SerializedRequest = { | ||
query?: string; | ||
variables?: Record<string, any>; | ||
operationName?: string; | ||
extensions?: any; | ||
}; | ||
type HeadersConfig = Record<string, string>; | ||
@@ -96,2 +102,2 @@ declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & { | ||
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode }; | ||
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SerializedRequest, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode }; |
@@ -1,4 +0,4 @@ | ||
import { createGraphQLError, mapMaybePromise, isAsyncIterable, isPromise, memoize1, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils'; | ||
import { isAsyncIterable, isPromise, mapMaybePromise, memoize1, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils'; | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
import { TextEncoder, crypto, File, FormData, TextDecoder, fetch } from '@whatwg-node/fetch'; | ||
import { File, FormData, TextEncoder, crypto, TextDecoder, fetch } from '@whatwg-node/fetch'; | ||
import { ValueOrPromise } from 'value-or-promise'; | ||
@@ -15,60 +15,2 @@ import { extractFiles, isExtractableFile } from 'extract-files'; | ||
function createAbortErrorReason() { | ||
return new Error("Executor was disposed."); | ||
} | ||
function createGraphQLErrorForAbort(reason, extensions) { | ||
return createGraphQLError("The operation was aborted. reason: " + reason, { | ||
extensions | ||
}); | ||
} | ||
function createResultForAbort(reason, extensions) { | ||
return { | ||
errors: [createGraphQLErrorForAbort(reason, extensions)] | ||
}; | ||
} | ||
function hashSHA256(str) { | ||
const textEncoder = new TextEncoder(); | ||
const utf8 = textEncoder.encode(str); | ||
return mapMaybePromise( | ||
crypto.subtle.digest("SHA-256", utf8), | ||
(hashBuffer) => { | ||
let hashHex = ""; | ||
for (const bytes of new Uint8Array(hashBuffer)) { | ||
hashHex += bytes.toString(16).padStart(2, "0"); | ||
} | ||
return hashHex; | ||
} | ||
); | ||
} | ||
function jsonStringifyBody(body) { | ||
let str = "{"; | ||
let prev = false; | ||
if (body.query) { | ||
str += `"query":"${body.query.replaceAll('"', '\\"')}"`; | ||
prev = true; | ||
} | ||
if (body.variables) { | ||
if (prev) { | ||
str += ","; | ||
} | ||
str += `"variables":${JSON.stringify(body.variables)}`; | ||
prev = true; | ||
} | ||
if (body.operationName) { | ||
if (prev) { | ||
str += ","; | ||
} | ||
str += `"operationName":"${body.operationName}"`; | ||
prev = true; | ||
} | ||
if (body.extensions) { | ||
if (prev) { | ||
str += ","; | ||
} | ||
str += `"extensions":${JSON.stringify(body.extensions)}`; | ||
} | ||
str += "}"; | ||
return str; | ||
} | ||
function collectAsyncIterableValues(asyncIterable) { | ||
@@ -95,6 +37,7 @@ const values = []; | ||
if (!body.variables) { | ||
return jsonStringifyBody(body); | ||
return JSON.stringify(body); | ||
} | ||
const vars = Object.assign({}, body.variables); | ||
const { clone, files } = extractFiles( | ||
body.variables, | ||
vars, | ||
"variables", | ||
@@ -104,3 +47,3 @@ (v) => isExtractableFile(v) || v?.promise || isAsyncIterable(v) || v?.then || typeof v?.arrayBuffer === "function" | ||
if (files.size === 0) { | ||
return jsonStringifyBody(body); | ||
return JSON.stringify(body); | ||
} | ||
@@ -118,3 +61,3 @@ const map = {}; | ||
"operations", | ||
jsonStringifyBody({ | ||
JSON.stringify({ | ||
...body, | ||
@@ -186,2 +129,30 @@ variables: clone | ||
function createAbortErrorReason() { | ||
return new Error("Executor was disposed."); | ||
} | ||
function createGraphQLErrorForAbort(reason, extensions) { | ||
return createGraphQLError("The operation was aborted. reason: " + reason, { | ||
extensions | ||
}); | ||
} | ||
function createResultForAbort(reason, extensions) { | ||
return { | ||
errors: [createGraphQLErrorForAbort(reason, extensions)] | ||
}; | ||
} | ||
function hashSHA256(str) { | ||
const textEncoder = new TextEncoder(); | ||
const utf8 = textEncoder.encode(str); | ||
return mapMaybePromise( | ||
crypto.subtle.digest("SHA-256", utf8), | ||
(hashBuffer) => { | ||
let hashHex = ""; | ||
for (const bytes of new Uint8Array(hashBuffer)) { | ||
hashHex += bytes.toString(16).padStart(2, "0"); | ||
} | ||
return hashHex; | ||
} | ||
); | ||
} | ||
const DELIM = "\n\n"; | ||
@@ -188,0 +159,0 @@ function isReadableStream(value) { |
{ | ||
"name": "@graphql-tools/executor-http", | ||
"version": "1.2.0-alpha-359d0599774929421e75780a3742aab822798dd2", | ||
"version": "1.2.0-alpha-52e7c9192bd3022251be5c3cabe546398300b30d", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "A set of utils for faster development of GraphQL tools", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
70118
1310