Skip to content

feat: pass abortSignal to resolvers #4261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2024
Merged

Conversation

yaacovCR
Copy link
Contributor

@yaacovCR yaacovCR commented Oct 27, 2024

this allows e.g. passing the signal to fetch

Note: the abortSignal is now the fifth argument to a GraphQLFieldResolverFn. If no resolver if provided, and the parent is an object with a key for the field name with a value that is a function, the abortSignal will be the fourth argument, as in the included test, with the parent accessible via the this keyword.

this allows e.g. passing the signal to fetch
@yaacovCR yaacovCR requested a review from a team as a code owner October 27, 2024 19:15
Copy link

netlify bot commented Oct 27, 2024

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit 2e0ce19
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/671f71d42ac6a10007571eb3
😎 Deploy Preview https://deploy-preview-4261--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@yaacovCR yaacovCR marked this pull request as draft October 27, 2024 19:16
@yaacovCR yaacovCR added the PR: feature 🚀 requires increase of "minor" version number label Oct 28, 2024
@yaacovCR yaacovCR marked this pull request as ready for review October 28, 2024 11:10
@yaacovCR yaacovCR merged commit 12a5ec9 into main Oct 28, 2024
35 checks passed
@yaacovCR yaacovCR deleted the pass-abort-signal-to-resolver branch October 28, 2024 11:17
@@ -990,6 +990,7 @@ export type GraphQLFieldResolver<
args: TArgs,
context: TContext,
info: GraphQLResolveInfo,
abortSignal: AbortSignal | undefined,
Copy link
Contributor

@glasser glasser Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yaacovCR I'm curious — how intentional is it that this was parameter defined as abortSignal: AbortSignal | undefined vs abortSignal?: AbortSignal? This means that any call in userland to a GraphQLFieldResolver (ie, that some user code may have plucked from a schema's field.resolve) will break if it doesn't explicitly pass in the signal.

In a sense I suppose that's good, because it means wrapping code (like this in Apollo Server) has to actually notice this new feature and not break it.

But I do wonder — why can't this just go on GraphQLResolveInfo rather than being a brand new field? To me, the arguments to a GraphQL-JS resolver have always felt like:

  • the parent/source
  • the arguments
  • a grab-bag object for whatever metadata the app developer wants available to resolvers
  • a grab-bag object for whatever metadata GraphQL JS wants available to resolvers

It feels like abortSignal fits perfectly fine on argument 4 without needing to have a brand new argument (which anything wrapping resolvers needs to pass through, etc). It also seems a bit more self-documenting to have the abortSignal come in an actual named field named abortSignal rather than just a 5th parameter.

(I think I suggested this back in 2022... I didn't realize the implementation didn't end up working that way.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glasser added a commit to glasser/graphql-js that referenced this pull request Jun 3, 2025
In graphql#4261 (not yet released in v17) we made abortSignal available to
resolvers via a fifth argument to the field resolver. Among other
things, this means that any code that processes schemas to wrap
resolvers in other functions would have to be aware of this one new
feature and specially thread through the new behavior. It also changed
the TypeScript signature of GraphQLFieldResolver to *require* passing
the fifth argument (even if undefined).

But the field resolver interface already has a place for GraphQL-JS to
put a grab-bag of helpful named objects for use by resolvers:
`GraphQLResolveInfo`.

This PR (which is not backwards compatible with v17.0.0-alpha.8, but is
backwards-compatible with v16) moves the abortSignal into
`GraphQLResolveInfo`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: feature 🚀 requires increase of "minor" version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants