-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Comments
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 |
@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 apollo-server/packages/apollo-server-plugin-base/src/index.ts Lines 39 to 44 in b3cbb42
If you were to return a |
Oh! didResolveOperation definetly resolves our use case! We were looking at the wrong hook! Thanks for the info! 🥇 |
I suspect most of this will be covered by the new request pipeline API, which is mostly |
Is there any value in supporting asynchronous handlers in Request Pipeline events?
Currently, some handlers are called asynchronously, the others - synchronously, e.g.:
Async sample:
apollo-server/packages/apollo-server-core/src/requestPipeline.ts
Lines 224 to 230 in 8b918e5
Sync sample (don't be confused with
await
-invokeDidStartHook
is synchronous):apollo-server/packages/apollo-server-core/src/requestPipeline.ts
Lines 232 to 238 in 8b918e5
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.The text was updated successfully, but these errors were encountered: