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

Asynchronous handlers in Request Pipeline #2062

Closed
AndreyChechel opened this issue Dec 4, 2018 · 4 comments
Closed

Asynchronous handlers in Request Pipeline #2062

AndreyChechel opened this issue Dec 4, 2018 · 4 comments

Comments

@AndreyChechel
Copy link

Is there any value in supporting asynchronous handlers in Request Pipeline events?

Currently, some handlers are called asynchronously, the others - synchronously, e.g.:

The scenario we've faced is, we'd like to use a plugin to start a DB transaction before execute function is called, and commit or rollback the transaction depending on whether the execution was successful or not.

The executionDidStart / executionDidEnd events look as good places where that logic could be implemented. The problem is handlers for the both events are invoked synchronously, thus, making us unable to await transaction actions to complete.

@ruizmarc
Copy link

We also have a use case in which we need to check the rate limit asynchronously based on the request of the user before executing the query. And at this moment, we cannot do it with the request pipeline as it is synchronous.

It would be great to have an asynchronous handler in the request pipeline :D

@abernix
Copy link
Member

abernix commented May 29, 2019

@ruizmarc The request pipeline is not all synchronous; this statement is untrue. Some life-cycle events are synchronous because they absolutely must be. Which request pipeline life-cycle method are you trying to use? I might suggest checking out didResolveOperation:

didResolveOperation?(
requestContext: WithRequired<
GraphQLRequestContext<TContext>,
'metrics' | 'source' | 'document' | 'operationName' | 'operation'
>,
): ValueOrPromise<void>;

If you were to return a Promise (or identically, implement that handler as an async function) you could prevent execution, if necessary, by throwing.

@ruizmarc
Copy link

Oh! didResolveOperation definetly resolves our use case! We were looking at the wrong hook!

Thanks for the info! 🥇

@abernix abernix added the 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged label Jul 8, 2019
@abernix
Copy link
Member

abernix commented Jul 8, 2019

I suspect most of this will be covered by the new request pipeline API, which is mostly async (whenever possible!). Please do take a look at #2008, which starts to document these new life-cycle hooks, and let us know if you don't find a hook that meets your needs. Thanks!

@abernix abernix closed this as completed Jul 8, 2019
@abernix abernix removed 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged labels Jul 9, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants