@graphql-tools/executor-http
Advanced tools
Comparing version 1.1.10-alpha-91b75cccda37b7789d695a4ddf72a1fb895c41c4 to 1.1.10-alpha-927a28ba2a92ca43d0d4a0032eb2d85f10eaf38c
# @graphql-tools/executor-http | ||
## 1.1.10-alpha-91b75cccda37b7789d695a4ddf72a1fb895c41c4 | ||
## 1.1.10-alpha-927a28ba2a92ca43d0d4a0032eb2d85f10eaf38c | ||
@@ -11,8 +11,2 @@ ### Patch Changes | ||
- [#180](https://github.com/graphql-hive/gateway/pull/180) [`c89efa9`](https://github.com/graphql-hive/gateway/commit/c89efa92f326f5d8759c70a241cfbe1d8c345a50) 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) [`48ad341`](https://github.com/graphql-hive/gateway/commit/48ad34115bc7ca36f9efb2b4d2ea43fd517320d6) Thanks [@ardatan](https://github.com/ardatan)! - Use new explicit resource management internally | ||
- [#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 +13,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ExecutionRequest, DisposableSyncExecutor, DisposableAsyncExecutor } from '@graphql-tools/utils'; | ||
import { ExecutionRequest, DisposableSyncExecutor, SyncExecutor, DisposableAsyncExecutor, AsyncExecutor } from '@graphql-tools/utils'; | ||
import { OperationDefinitionNode, GraphQLResolveInfo, DocumentNode } from 'graphql'; | ||
@@ -59,3 +59,4 @@ | ||
/** | ||
* @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) | ||
* @default false | ||
*/ | ||
@@ -65,13 +66,43 @@ disposable?: boolean; | ||
type HeadersConfig = Record<string, string>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & { | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
fetch: SyncFetchFn; | ||
disposable: true; | ||
}): DisposableSyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
fetch: SyncFetchFn; | ||
disposable: false; | ||
}): SyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & { | ||
fetch: SyncFetchFn; | ||
}): SyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
fetch: AsyncFetchFn; | ||
disposable: true; | ||
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
fetch: AsyncFetchFn; | ||
disposable: false; | ||
}): AsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & { | ||
fetch: AsyncFetchFn; | ||
}): AsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
fetch: RegularFetchFn; | ||
disposable: true; | ||
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): DisposableAsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
fetch: RegularFetchFn; | ||
disposable: false; | ||
}): AsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'> & { | ||
fetch: RegularFetchFn; | ||
}): AsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
disposable: true; | ||
}): DisposableAsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch' | 'disposable'> & { | ||
disposable: false; | ||
}): AsyncExecutor<any, HTTPExecutorOptions>; | ||
declare function buildHTTPExecutor(options?: Omit<HTTPExecutorOptions, 'fetch'>): AsyncExecutor<any, HTTPExecutorOptions>; | ||
export { type AsyncFetchFn, type AsyncImportFn, type FetchFn, type HTTPExecutorOptions, type HeadersConfig, type RegularFetchFn, type SyncFetchFn, type SyncImportFn, type SyncResponse, buildHTTPExecutor, isLiveQueryOperationDefinitionNode }; |
@@ -1,3 +0,2 @@ | ||
import { isAsyncIterable, isPromise, fakePromise, createGraphQLError, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest } from '@graphql-tools/utils'; | ||
import { DisposableSymbols } from '@whatwg-node/disposablestack'; | ||
import { isAsyncIterable, isPromise, fakePromise, inspect, mapAsyncIterator, mergeIncrementalResult, memoize1, getOperationASTFromRequest, createGraphQLError } from '@graphql-tools/utils'; | ||
import { File, FormData, TextDecoder, fetch } from '@whatwg-node/fetch'; | ||
@@ -112,16 +111,2 @@ import { ValueOrPromise } from 'value-or-promise'; | ||
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)] | ||
}; | ||
} | ||
const DELIM = "\n\n"; | ||
@@ -131,3 +116,3 @@ function isReadableStream(value) { | ||
} | ||
function handleEventStreamResponse(signal, response) { | ||
function handleEventStreamResponse(response) { | ||
const body = response.body; | ||
@@ -148,6 +133,2 @@ if (!isReadableStream(body)) { | ||
async function pump() { | ||
if (signal.aborted) { | ||
await push(createResultForAbort(signal)); | ||
return stop(); | ||
} | ||
if (!body?.locked) { | ||
@@ -252,25 +233,8 @@ return stop(); | ||
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); | ||
let disposeCtrl; | ||
const baseExecutor = (request) => { | ||
if (sharedSignal.aborted) { | ||
return createResultForAbort(sharedSignal.reason); | ||
if (disposeCtrl?.signal.aborted) { | ||
return createResultForAbort(disposeCtrl.signal); | ||
} | ||
@@ -305,8 +269,18 @@ const fetchFn = request.extensions?.fetch ?? options?.fetch ?? fetch; | ||
const query = printFn(request.document); | ||
let signal = sharedSignal; | ||
let signal = disposeCtrl?.signal; | ||
let clearTimeoutFn = () => { | ||
}; | ||
if (options?.timeout) { | ||
signal = AbortSignal.any([ | ||
sharedSignal, | ||
AbortSignal.timeout(options.timeout) | ||
]); | ||
const timeoutCtrl = new AbortController(); | ||
signal = timeoutCtrl.signal; | ||
disposeCtrl?.signal.addEventListener("abort", clearTimeoutFn); | ||
const timeoutId = setTimeout(() => { | ||
if (!timeoutCtrl.signal.aborted) { | ||
timeoutCtrl.abort("timeout"); | ||
} | ||
disposeCtrl?.signal.removeEventListener("abort", clearTimeoutFn); | ||
}, options.timeout); | ||
clearTimeoutFn = () => { | ||
clearTimeout(timeoutId); | ||
}; | ||
} | ||
@@ -384,2 +358,3 @@ const upstreamErrorExtensions = { | ||
}); | ||
clearTimeoutFn(); | ||
if (options?.retry != null && !fetchResult.status.toString().startsWith("2")) { | ||
@@ -392,3 +367,3 @@ throw new Error( | ||
if (contentType?.includes("text/event-stream")) { | ||
return handleEventStreamResponse(signal, fetchResult); | ||
return handleEventStreamResponse(fetchResult); | ||
} else if (contentType?.includes("multipart/mixed")) { | ||
@@ -481,4 +456,4 @@ return handleMultipartMixedResponse(fetchResult); | ||
function retryAttempt() { | ||
if (sharedSignal.aborted) { | ||
return createResultForAbort(sharedSignal.reason); | ||
if (disposeCtrl?.signal.aborted) { | ||
return createResultForAbort(disposeCtrl.signal); | ||
} | ||
@@ -505,4 +480,9 @@ attempt++; | ||
} | ||
if (!options?.disposable) { | ||
disposeCtrl = void 0; | ||
return executor; | ||
} | ||
disposeCtrl = new AbortController(); | ||
Object.defineProperties(executor, { | ||
[DisposableSymbols.dispose]: { | ||
[Symbol.dispose]: { | ||
get() { | ||
@@ -514,3 +494,3 @@ return function dispose() { | ||
}, | ||
[DisposableSymbols.asyncDispose]: { | ||
[Symbol.asyncDispose]: { | ||
get() { | ||
@@ -541,4 +521,4 @@ return function asyncDispose() { | ||
}); | ||
} else if (e.name === "AbortError" && signal.reason) { | ||
return createGraphQLErrorForAbort(signal.reason, { | ||
} else if (e.name === "AbortError" && signal?.reason) { | ||
return createGraphQLErrorForAbort(signal, { | ||
extensions: upstreamErrorExtensions | ||
@@ -558,3 +538,19 @@ }); | ||
} | ||
function createAbortErrorReason() { | ||
return new Error("Executor was disposed."); | ||
} | ||
function createGraphQLErrorForAbort(signal, extensions) { | ||
return createGraphQLError( | ||
"The operation was aborted. reason: " + signal.reason, | ||
{ | ||
extensions | ||
} | ||
); | ||
} | ||
function createResultForAbort(signal, extensions) { | ||
return { | ||
errors: [createGraphQLErrorForAbort(signal, extensions)] | ||
}; | ||
} | ||
export { buildHTTPExecutor, isLiveQueryOperationDefinitionNode }; |
{ | ||
"name": "@graphql-tools/executor-http", | ||
"version": "1.1.10-alpha-91b75cccda37b7789d695a4ddf72a1fb895c41c4", | ||
"version": "1.1.10-alpha-927a28ba2a92ca43d0d4a0032eb2d85f10eaf38c", | ||
"type": "module", | ||
@@ -44,3 +44,2 @@ "description": "A set of utils for faster development of GraphQL tools", | ||
"@repeaterjs/repeater": "^3.0.4", | ||
"@whatwg-node/disposablestack": "^0.0.5", | ||
"@whatwg-node/fetch": "^0.10.0", | ||
@@ -47,0 +46,0 @@ "extract-files": "^11.0.0", |
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
62596
8
1175
- Removed@whatwg-node/disposablestack@^0.0.5