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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach AbortSignal to context by default 馃 #2207

Open
Tracked by #1358
n1ru4l opened this issue Dec 6, 2022 · 1 comment
Open
Tracked by #1358

Attach AbortSignal to context by default 馃 #2207

n1ru4l opened this issue Dec 6, 2022 · 1 comment

Comments

@n1ru4l
Copy link
Collaborator

n1ru4l commented Dec 6, 2022

This would be handy for canceling ongoing stuff within GraphQL resolvers 馃

@robertherber
Copy link

robertherber commented May 14, 2023

This would be awesome 馃憤 I think I can provide some useful input on which capabilities would be nice since I'm currently setting working with AbortSignals in our Fastify/Yoga/GraphQL/MongoDB environment. Our use case is working with large datasets we sometimes trigger really slow queries, and as such want to cancel all requests (including database requests) after a certain timeout to clear up resources. Aborting on "client closed" is also nice but in our case not the main use case.

As a whole I'd like a solution that supports these scenarios:

  • Exposing an AbortSignal through context so it can be used on any API supporting it in the resolvers (the obvious part I guess). This is fairly easy to do "manually" but having a standard would be nice.
  • Make sure the AbortSignal prevents any new resolvers from triggering after an abort, this is something I haven't looked into but would be very nice I think.
  • Make it possible to specify a request timeout for the AbortSignal.
  • Be able to access how much time is left until this timeout (MongoDB for example doesn't support AbortSignal but can be called with cursor.maxTimeMS(ms) to ensure it times out)
  • It would be nice to be able to "bring your own" AbortSignal, if you want to handle the specifics on a web server level (ex: in the timeout case I feel it makes sense to initialize the AbortSignal onRequest in my Fastify server, and it also supports our REST routes).
  • Handling the abort response in a standard manner. I'm currently leaning towards plain HTTP 504 (Gateway Timeout) and 499 (Client Closed) responses since it would deal with all cases the same way.

I'm thinking to keep things simple one option would for Yoga to initially just provide:

  1. A standard way to pass the AbortSignal to resolvers through context (i.e. you have to "bring your own" AbortSignal)
  2. Preventing new resolvers from triggering after an abort

And maybe at a later stage provide a default AbortSignal implementation supporting the request timeout and client closed cases? What do you think?

This was referenced May 7, 2024
This was referenced May 23, 2024
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