@graphql-tools/executor-http
Advanced tools
Comparing version 1.1.10-alpha-ad751f582d666319969a93908c275a311e180023 to 1.1.10-alpha-b6336a438a693900497d519282bf97cd70eeb27d
# @graphql-tools/executor-http | ||
## 1.1.10-alpha-ad751f582d666319969a93908c275a311e180023 | ||
## 1.1.10-alpha-b6336a438a693900497d519282bf97cd70eeb27d | ||
@@ -11,8 +11,10 @@ ### Patch Changes | ||
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`ad751f5`](https://github.com/graphql-hive/gateway/commit/ad751f582d666319969a93908c275a311e180023) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates: | ||
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`9438e21`](https://github.com/graphql-hive/gateway/commit/9438e21982ed5c6fb18cb678b275046595ae00f5) Thanks [@ardatan](https://github.com/ardatan)! - dependencies updates: | ||
- Added dependency [`@whatwg-node/disposablestack@^0.0.5` ↗︎](https://www.npmjs.com/package/@whatwg-node/disposablestack/v/0.0.5) (to `dependencies`) | ||
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`875cbc6`](https://github.com/graphql-hive/gateway/commit/875cbc620ba05d4e04cd368bf3e530a59352bf5f) Thanks [@ardatan](https://github.com/ardatan)! - Use new explicit resource management internally | ||
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`9438e21`](https://github.com/graphql-hive/gateway/commit/9438e21982ed5c6fb18cb678b275046595ae00f5) Thanks [@ardatan](https://github.com/ardatan)! - Use new explicit resource management internally | ||
- [#199](https://github.com/graphql-hive/gateway/pull/199) [`b534288`](https://github.com/graphql-hive/gateway/commit/b5342885f8ac1197d70cbf45266c83b720b4f85a) Thanks [@ardatan](https://github.com/ardatan)! - Logs are now easier to read, bigger results not do not create bigger outputs but instead they are all logged in a single line | ||
- [#98](https://github.com/graphql-hive/gateway/pull/98) [`697308d`](https://github.com/graphql-hive/gateway/commit/697308df3b2dd96f28dc65a5f5361a911077e022) Thanks [@ardatan](https://github.com/ardatan)! - Bun support by using native Bun API whenever possible | ||
@@ -19,0 +21,0 @@ |
@@ -59,3 +59,4 @@ import { ExecutionRequest, DisposableSyncExecutor, DisposableAsyncExecutor } from '@graphql-tools/utils'; | ||
/** | ||
* @deprecated Not used anymore | ||
* Enable [Explicit Resource Management](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management) | ||
* @deprecated The executors are always disposable, and this option will be removed in the next major version, there is no need to have a flag for this. | ||
*/ | ||
@@ -62,0 +63,0 @@ disposable?: boolean; |
@@ -1,2 +0,2 @@ | ||
import { isAsyncIterable, isPromise, fakePromise, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest } from '@graphql-tools/utils'; | ||
import { isAsyncIterable, isPromise, fakePromise, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest, mapMaybePromise } from '@graphql-tools/utils'; | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
@@ -60,3 +60,3 @@ import { File, FormData, TextDecoder, fetch } from '@whatwg-node/fetch'; | ||
); | ||
form.append("map", JSON.stringify(map, null, 2)); | ||
form.append("map", JSON.stringify(map)); | ||
function handleUpload(upload, i) { | ||
@@ -93,7 +93,14 @@ const indexStr = i.toString(); | ||
} | ||
return ValueOrPromise.all( | ||
uploads.map( | ||
(upload, i) => new ValueOrPromise(() => handleUpload(upload, i)) | ||
) | ||
).then(() => form).resolve(); | ||
const jobs = []; | ||
for (const i in uploads) { | ||
const upload = uploads[i]; | ||
const job = handleUpload(upload, Number(i)); | ||
if (isPromise(job)) { | ||
jobs.push(job); | ||
} | ||
} | ||
if (jobs.length > 0) { | ||
return Promise.all(jobs).then(() => form); | ||
} | ||
return form; | ||
} | ||
@@ -117,13 +124,10 @@ function isBlob(obj) { | ||
} | ||
function createGraphQLErrorForAbort(signal, extensions) { | ||
return createGraphQLError( | ||
"The operation was aborted. reason: " + signal.reason, | ||
{ | ||
extensions | ||
} | ||
); | ||
function createGraphQLErrorForAbort(reason, extensions) { | ||
return createGraphQLError("The operation was aborted. reason: " + reason, { | ||
extensions | ||
}); | ||
} | ||
function createResultForAbort(signal, extensions) { | ||
function createResultForAbort(reason, extensions) { | ||
return { | ||
errors: [createGraphQLErrorForAbort(signal, extensions)] | ||
errors: [createGraphQLErrorForAbort(reason, extensions)] | ||
}; | ||
@@ -255,8 +259,25 @@ } | ||
function createSignalWrapper(signal) { | ||
const listeners = /* @__PURE__ */ new Set(); | ||
signal.onabort = (event) => { | ||
for (const listener of listeners) { | ||
listener(event); | ||
} | ||
}; | ||
return Object.assign(signal, { | ||
addEventListener(_type, listener) { | ||
listeners.add(listener); | ||
}, | ||
removeEventListener(_type, listener) { | ||
listeners.delete(listener); | ||
} | ||
}); | ||
} | ||
function buildHTTPExecutor(options) { | ||
const printFn = options?.print ?? defaultPrintFn; | ||
const disposeCtrl = new AbortController(); | ||
const sharedSignal = createSignalWrapper(disposeCtrl.signal); | ||
const baseExecutor = (request) => { | ||
if (disposeCtrl.signal.aborted) { | ||
return createResultForAbort(disposeCtrl.signal); | ||
if (sharedSignal.aborted) { | ||
return createResultForAbort(sharedSignal.reason); | ||
} | ||
@@ -291,5 +312,8 @@ const fetchFn = request.extensions?.fetch ?? options?.fetch ?? fetch; | ||
const query = printFn(request.document); | ||
let signal = disposeCtrl.signal; | ||
let signal = sharedSignal; | ||
if (options?.timeout) { | ||
signal = AbortSignal.any([signal, AbortSignal.timeout(options.timeout)]); | ||
signal = AbortSignal.any([ | ||
sharedSignal, | ||
AbortSignal.timeout(options.timeout) | ||
]); | ||
} | ||
@@ -331,28 +355,29 @@ const upstreamErrorExtensions = { | ||
upstreamErrorExtensions.request.body = body; | ||
return new ValueOrPromise( | ||
() => createFormDataFromVariables(body, { | ||
return mapMaybePromise( | ||
createFormDataFromVariables(body, { | ||
File: options?.File, | ||
FormData: options?.FormData | ||
}) | ||
).then((body2) => { | ||
if (typeof body2 === "string" && !headers["content-type"]) { | ||
upstreamErrorExtensions.request.body = body2; | ||
headers["content-type"] = "application/json"; | ||
}), | ||
(body2) => { | ||
if (typeof body2 === "string" && !headers["content-type"]) { | ||
upstreamErrorExtensions.request.body = body2; | ||
headers["content-type"] = "application/json"; | ||
} | ||
const fetchOptions = { | ||
method: "POST", | ||
body: body2, | ||
headers, | ||
signal | ||
}; | ||
if (options?.credentials != null) { | ||
fetchOptions.credentials = options.credentials; | ||
} | ||
return fetchFn( | ||
endpoint, | ||
fetchOptions, | ||
request.context, | ||
request.info | ||
); | ||
} | ||
const fetchOptions = { | ||
method: "POST", | ||
body: body2, | ||
headers, | ||
signal | ||
}; | ||
if (options?.credentials != null) { | ||
fetchOptions.credentials = options.credentials; | ||
} | ||
return fetchFn( | ||
endpoint, | ||
fetchOptions, | ||
request.context, | ||
request.info | ||
); | ||
}).resolve(); | ||
); | ||
} | ||
@@ -463,4 +488,4 @@ } | ||
function retryAttempt() { | ||
if (disposeCtrl?.signal.aborted) { | ||
return createResultForAbort(disposeCtrl.signal); | ||
if (sharedSignal.aborted) { | ||
return createResultForAbort(sharedSignal.reason); | ||
} | ||
@@ -476,3 +501,3 @@ attempt++; | ||
} | ||
return new ValueOrPromise(() => baseExecutor(request)).then((res) => { | ||
return mapMaybePromise(baseExecutor(request), (res) => { | ||
result = res; | ||
@@ -483,3 +508,3 @@ if (result?.errors?.length) { | ||
return result; | ||
}).resolve(); | ||
}); | ||
} | ||
@@ -524,3 +549,3 @@ return retryAttempt(); | ||
} else if (e.name === "AbortError" && signal.reason) { | ||
return createGraphQLErrorForAbort(signal, { | ||
return createGraphQLErrorForAbort(signal.reason, { | ||
extensions: upstreamErrorExtensions | ||
@@ -527,0 +552,0 @@ }); |
{ | ||
"name": "@graphql-tools/executor-http", | ||
"version": "1.1.10-alpha-ad751f582d666319969a93908c275a311e180023", | ||
"version": "1.1.10-alpha-b6336a438a693900497d519282bf97cd70eeb27d", | ||
"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
61361
1167