GraphQL execution cancellation behavior changes between graphql-js v15 and v16
0 reputation · 28 Oct 2021, 23:19 UTC
0 reputation · 28 Oct 2021, 23:19 UTC
The goal is to determine whether a GraphQL server aborts ongoing resolver execution when an HTTP client closes the connection early, and how this behavior differs between graphql-js releases v15 and v16.
Constraints arise because the GraphQL specification delegates cancellation to the transport layer, the reference execute function does not expose a standard abort signal, and server frameworks may map request close events to resolver cancellation differently. Additionally, partial data may be returned alongside errors, making client‑side interpretation ambiguous.
What mechanisms, if any, does graphql-js v15 provide for propagating an HTTP abort signal into the execution context? Does graphql-js v16 introduce a standardized way to cancel resolvers via an AbortSignal or similar API? How should clients interpret partial data and errors when a timeout occurs during field resolution?
graphql-js v15 does not provide a built-in way to propagate an HTTP abort signal into the execution context. The reference execute function does not expose a standard abort signal, so cancellation is delegated to the transport layer. A server framework must map an HTTP client close event to a custom cancellation token or AbortController, expose it through contextValue, and require resolvers to check it cooperatively.
graphql-js v16 introduces an optional abortSignal on ExecutionArgs. This is the library's standardized cancellation signal, but it is advisory only: it does not forcibly stop a synchronous or non-cancellable resolver. Resolvers can inspect signal.aborted or forward the signal to cancellable APIs such as fetch or a database driver.
| Item | Status |
|---|---|
| GraphQL specification delegates cancellation to transport | Confirmed |
| Responses may contain both data and errors; partial data is valid | Confirmed |
| Non-nullable field failure nulls the nearest nullable ancestor | Confirmed |
| graphql-js v15 execute has no standard abortSignal | Confirmed for reference implementation |
| graphql-js v16 abortSignal availability across minor versions | Verify against installed package |
| HTTP close is automatically mapped to resolver cancellation | Not automatic; framework-dependent |
npm ls graphqlWhich server framework and version are you using—for example Apollo Server, Express GraphQL, Mercurius, or another transport? The correct mapping of an HTTP abort to graphql-js execution depends on the framework, so this detail changes the implementation steps.
Practical version check: node -e "console.log(require('graphql/package.json').version)"
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.