Comparing version 17.0.0-alpha.3 to 17.0.0-alpha.3.canary.pr.3791.4a8f641106bee54f1e4a4de4bf59c49976541b00
@@ -0,1 +1,2 @@ | ||
import type { IAbortSignal } from '../jsutils/AbortController.js'; | ||
import type { Maybe } from '../jsutils/Maybe.js'; | ||
@@ -63,2 +64,3 @@ import type { ObjMap } from '../jsutils/ObjMap.js'; | ||
incrementalPublisher: IncrementalPublisher; | ||
executionController: ExecutionController; | ||
} | ||
@@ -77,2 +79,3 @@ export interface ExecutionArgs { | ||
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>; | ||
signal?: IAbortSignal | undefined; | ||
} | ||
@@ -136,2 +139,12 @@ export interface StreamUsage { | ||
): ReadonlyArray<GraphQLError> | ExecutionContext; | ||
declare class ExecutionController { | ||
/** For performance reason we can't use `signal.isAborted` so we cache it here */ | ||
isAborted: boolean; | ||
private readonly _passedInAbortSignal; | ||
private readonly _abortController; | ||
constructor(signal?: IAbortSignal); | ||
get signal(): IAbortSignal | undefined; | ||
abort(reason?: unknown): void; | ||
private readonly _abortCB; | ||
} | ||
/** | ||
@@ -231,1 +244,2 @@ * TODO: consider no longer exporting this function | ||
): PromiseOrValue<AsyncIterable<unknown> | ExecutionResult>; | ||
export {}; |
@@ -183,2 +183,3 @@ 'use strict'; | ||
subscribeFieldResolver, | ||
signal, | ||
} = args; | ||
@@ -246,5 +247,31 @@ // If the schema used for execution is invalid, throw an error. | ||
incrementalPublisher: new IncrementalPublisher_js_1.IncrementalPublisher(), | ||
executionController: new ExecutionController(signal), | ||
}; | ||
} | ||
exports.buildExecutionContext = buildExecutionContext; | ||
class ExecutionController { | ||
/* c8 ignore stop */ | ||
constructor(signal) { | ||
/** For performance reason we can't use `signal.isAborted` so we cache it here */ | ||
this.isAborted = false; | ||
// We don't have AbortController in node 14 so we need to use this hack | ||
// It can be removed once we drop support for node 14 | ||
/* c8 ignore start */ | ||
this._abortController = | ||
typeof AbortController !== 'undefined' | ||
? new AbortController() | ||
: undefined; | ||
this._abortCB = (event) => this.abort(event.target.reason); | ||
this._passedInAbortSignal = signal; | ||
this._passedInAbortSignal?.addEventListener('abort', this._abortCB); | ||
} | ||
get signal() { | ||
return this._abortController?.signal; | ||
} | ||
abort(reason) { | ||
this._passedInAbortSignal?.removeEventListener('abort', this._abortCB); | ||
this._abortController?.abort(reason); | ||
this.isAborted = true; | ||
} | ||
} | ||
function buildPerEventExecutionContext(exeContext, payload) { | ||
@@ -254,2 +281,5 @@ return { | ||
rootValue: payload, | ||
executionController: new ExecutionController( | ||
exeContext.executionController.signal, | ||
), | ||
}; | ||
@@ -480,2 +510,5 @@ } | ||
try { | ||
if (exeContext.executionController.isAborted) { | ||
exeContext.executionController.signal?.throwIfAborted(); | ||
} | ||
// Build a JS object of arguments from the field.arguments AST, using the | ||
@@ -564,2 +597,3 @@ // variables scope to fulfill any variable references. | ||
variableValues: exeContext.variableValues, | ||
signal: exeContext.executionController.signal, | ||
}; | ||
@@ -1451,2 +1485,15 @@ } | ||
function subscribe(args) { | ||
// Until we have execution cancelling support in Subscriptions, | ||
// throw an error if client provides abort signal. | ||
/* c8 ignore start */ | ||
if (args.signal) { | ||
return { | ||
errors: [ | ||
new GraphQLError_js_1.GraphQLError( | ||
'Subscriptions do not support abort signals.', | ||
), | ||
], | ||
}; | ||
} | ||
/* c8 ignore stop */ | ||
// If a valid execution context cannot be created due to incorrect arguments, | ||
@@ -1482,2 +1529,3 @@ // a "Response" with only errors is returned. | ||
executeImpl(buildPerEventExecutionContext(exeContext, payload)), | ||
() => exeContext.executionController.abort(), | ||
); | ||
@@ -1571,2 +1619,9 @@ } | ||
try { | ||
// Until we have execution cancelling support in Subscriptions, | ||
// ignore test coverage. | ||
/* c8 ignore start */ | ||
if (exeContext.executionController.isAborted) { | ||
exeContext.executionController.signal?.throwIfAborted(); | ||
} | ||
/* c8 ignore stop */ | ||
// Implements the "ResolveFieldEventStream" algorithm from GraphQL specification. | ||
@@ -1573,0 +1628,0 @@ // It differs from "ResolveFieldValue" due to providing a different `resolveFn`. |
@@ -8,3 +8,4 @@ import type { PromiseOrValue } from '../jsutils/PromiseOrValue.js'; | ||
iterable: AsyncGenerator<T, R, void> | AsyncIterable<T>, | ||
callback: (value: T) => PromiseOrValue<U>, | ||
valueCallback: (value: T) => PromiseOrValue<U>, | ||
finallyCallback: () => void, | ||
): AsyncGenerator<U, R, void>; |
@@ -8,10 +8,11 @@ 'use strict'; | ||
*/ | ||
function mapAsyncIterable(iterable, callback) { | ||
function mapAsyncIterable(iterable, valueCallback, finallyCallback) { | ||
const iterator = iterable[Symbol.asyncIterator](); | ||
async function mapResult(result) { | ||
if (result.done) { | ||
finallyCallback(); | ||
return result; | ||
} | ||
try { | ||
return { value: await callback(result.value), done: false }; | ||
return { value: await valueCallback(result.value), done: false }; | ||
} catch (error) { | ||
@@ -37,5 +38,7 @@ /* c8 ignore start */ | ||
// If iterator.return() does not exist, then type R must be undefined. | ||
return typeof iterator.return === 'function' | ||
? mapResult(await iterator.return()) | ||
: { value: undefined, done: true }; | ||
const result = | ||
typeof iterator.return === 'function' | ||
? await iterator.return() | ||
: { value: undefined, done: true }; | ||
return mapResult(result); | ||
}, | ||
@@ -46,2 +49,3 @@ async throw(error) { | ||
} | ||
finallyCallback(); | ||
throw error; | ||
@@ -48,0 +52,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
import type { IAbortSignal } from './jsutils/AbortController.js'; | ||
import type { Maybe } from './jsutils/Maybe.js'; | ||
@@ -49,2 +50,5 @@ import type { Source } from './language/source.js'; | ||
* `__typename` field or alternatively calls the `isTypeOf` method). | ||
* signal: | ||
* An AbortSignal that can be used to abort the execution of the query. | ||
* If the signal is aborted, the execution will stop and an abort error will be thrown. | ||
*/ | ||
@@ -62,2 +66,3 @@ export interface GraphQLArgs { | ||
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>; | ||
signal?: IAbortSignal; | ||
} | ||
@@ -64,0 +69,0 @@ export declare function graphql(args: GraphQLArgs): Promise<ExecutionResult>; |
@@ -39,2 +39,3 @@ 'use strict'; | ||
typeResolver, | ||
signal, | ||
} = args; | ||
@@ -68,3 +69,4 @@ // Validate Schema | ||
typeResolver, | ||
signal, | ||
}); | ||
} |
{ | ||
"name": "graphql", | ||
"version": "17.0.0-alpha.3", | ||
"version": "17.0.0-alpha.3.canary.pr.3791.4a8f641106bee54f1e4a4de4bf59c49976541b00", | ||
"description": "A Query Language and Runtime which can target any service.", | ||
@@ -35,6 +35,7 @@ "license": "MIT", | ||
"publishConfig": { | ||
"tag": "alpha" | ||
"tag": "canary-pr-3791" | ||
}, | ||
"main": "index", | ||
"module": "index.mjs" | ||
} | ||
"module": "index.mjs", | ||
"deprecated": "You are using canary version build from https://github.com/graphql/graphql-js/pull/3791, no gurantees provided so please use your own discretion." | ||
} |
@@ -0,1 +1,2 @@ | ||
import type { IAbortSignal } from '../jsutils/AbortController.js'; | ||
import type { Maybe } from '../jsutils/Maybe.js'; | ||
@@ -470,2 +471,7 @@ import type { ObjMap } from '../jsutils/ObjMap.js'; | ||
}; | ||
/** | ||
* Note: signal is undefined only if execution environment doesn't support | ||
* AbortController (e.g. node14 without polyfill). | ||
*/ | ||
readonly signal: IAbortSignal | undefined; | ||
} | ||
@@ -472,0 +478,0 @@ /** |
Sorry, the diff of this file is not supported yet
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
1439635
412
44432
1