Skip to content
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

Allow execution to be cancelled #3764

Closed
glasser opened this issue Oct 20, 2022 · 1 comment
Closed

Allow execution to be cancelled #3764

glasser opened this issue Oct 20, 2022 · 1 comment

Comments

@glasser
Copy link
Contributor

glasser commented Oct 20, 2022

Once execution begins, there's no way to stop it from running until completion.

However, servers may want to be able to stop execution. For example:

  • Servers may have a response timeout; there's no use continuing to execute fields after the server has returned a "request timed out" error.
  • Servers may want to avoid OOM attacks via nested lists by dynamically enforcing a maximum number of resolved fields and cancelling once too many fields have been resolved.

It would be helpful if execute (and experimentalExecuteIncrementally, etc) had a mechanism for cancelling execution. This could be based on web-style AbortSignal/AbortController or a different API style.

JoviDeCroock added a commit that referenced this issue Oct 23, 2024
This adds support for aborting execution from the outside or resolvers,
this adds a few tests and tries to make the support as easy as possible.

Do we want to support having abort support on subscriptions, I guess it
makes sense for server-sent events.

I've chosen 2 places to place these interrupts

- `executeFieldsSerially` - every time we start a new mutation we check
whether the runtime has interrupted
- `executeFields` - every time we start executing a new field we check
whether the runtime has interrupted
- inside of the catch block as well so we return a singular error, all
though this doesn't really matter as the consumer would not receive
anything
  - this here should also take care of deferred fields

When comparing this to `graphql-tools/execute` I am not sure whether we
want to match this behavior, this throws a DomException which would be a
whole new exception that gets thrown while normally during execution we
wrap everything with GraphQLErrors.

Supersedes #3791
Resolves #3764

Co-authored-by: yaacovCR <yaacovCR@gmail.com>
@JoviDeCroock
Copy link
Member

Implemented in #4250 and slated for v17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants