@graphql-tools/executor-http
Advanced tools
Comparing version 1.2.0-alpha-52e7c9192bd3022251be5c3cabe546398300b30d to 1.2.0-alpha-66d4b92ec6c93cfa4098b6caf98cffd89e210038
# @graphql-tools/executor-http | ||
## 1.2.0-alpha-52e7c9192bd3022251be5c3cabe546398300b30d | ||
## 1.2.0-alpha-66d4b92ec6c93cfa4098b6caf98cffd89e210038 | ||
@@ -5,0 +5,0 @@ ### Minor Changes |
@@ -83,8 +83,2 @@ 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>; | ||
@@ -102,2 +96,2 @@ declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & { | ||
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SerializedRequest, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode }; | ||
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode }; |
@@ -1,4 +0,4 @@ | ||
import { isAsyncIterable, isPromise, mapMaybePromise, memoize1, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils'; | ||
import { createGraphQLError, mapMaybePromise, isAsyncIterable, isPromise, memoize1, inspect, mapAsyncIterator, mergeIncrementalResult, getOperationASTFromRequest } from '@graphql-tools/utils'; | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
import { File, FormData, TextEncoder, crypto, TextDecoder, fetch } from '@whatwg-node/fetch'; | ||
import { TextEncoder, crypto, File, FormData, TextDecoder, fetch } from '@whatwg-node/fetch'; | ||
import { ValueOrPromise } from 'value-or-promise'; | ||
@@ -15,2 +15,60 @@ 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) { | ||
@@ -37,7 +95,6 @@ const values = []; | ||
if (!body.variables) { | ||
return JSON.stringify(body); | ||
return jsonStringifyBody(body); | ||
} | ||
const vars = Object.assign({}, body.variables); | ||
const { clone, files } = extractFiles( | ||
vars, | ||
body.variables, | ||
"variables", | ||
@@ -47,3 +104,3 @@ (v) => isExtractableFile(v) || v?.promise || isAsyncIterable(v) || v?.then || typeof v?.arrayBuffer === "function" | ||
if (files.size === 0) { | ||
return JSON.stringify(body); | ||
return jsonStringifyBody(body); | ||
} | ||
@@ -61,3 +118,3 @@ const map = {}; | ||
"operations", | ||
JSON.stringify({ | ||
jsonStringifyBody({ | ||
...body, | ||
@@ -129,30 +186,2 @@ 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"; | ||
@@ -159,0 +188,0 @@ function isReadableStream(value) { |
{ | ||
"name": "@graphql-tools/executor-http", | ||
"version": "1.2.0-alpha-52e7c9192bd3022251be5c3cabe546398300b30d", | ||
"version": "1.2.0-alpha-66d4b92ec6c93cfa4098b6caf98cffd89e210038", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70980
1362