-
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
requestDidStart hook not called if context creation failes #3039
Comments
Thanks for reporting this issue! It's possible this has been resolved, but I can't be certain because there's no reproduction here to try quickly. As requested in the issue template when you submitted this issue, GitHub Issues need to include simple, runnable reproductions. This means either a GitHub repository that anyone can clone and run and see the problem or an example built using the Apollo Server CodeSandbox template or by "re-mixing" the Apollo Server Glitch template. Building reproductions takes a large portion of core contributor's and issue triager's time and without a runnable reproduction, we'll have to close this issue in the next 7 days. Hope you understand! If you aren't able to supply a runnable reproduction, we're happy to re-open this later on when one can be provided. Regardless, thanks again for filing the issue since, reproduction or not, this information could be useful for a future visitor! |
I have the same issue where the requestDidStart hook is not called, here's the reproduction I made. It cause the code you provide here to not work because the plugin is never called. Hope it will help! |
+1 I'm having the exact same issue as @cbdt. Please just let us know if we're doing something wrong or if the hook is not working as intended. |
I'm having the same issue as well. |
any progress on this? |
cannot believe it is still not done... |
Fixing this is a challenge because of the way the codebase is currently structured. Apollo Server 1 was built as a set of standalone functions; the ApolloServer class was only introduced in Apollo Server 2. The structure of the code is that the ApolloServer class takes its internal state and produces a pretty complex object that it passes to the standalone runHttpQuery function, which then calls the processGraphQLRequest function. Calling the context function happens via some weird machinery coordinated by the As a work-around, you can ensure that your context function does not throw, with something like:
|
This is not so good because if i rethrow in |
Even if you throw an HttpQueryError? |
No I am rethrowing original error that was caought in context - AuthenticationError
|
If you care about the HTTP status code, you should throw HttpQueryError. |
Nop. I tried HttpQueryError but ststaus code was 500
|
Works for me, with something like
Happy to look into this further if you can show a complete reproduction (eg, on codesandbox.io or with |
intersting because for me it is
but I am using apollo-server-express so maybe this is the reason |
Happy to look into it more with a full reproduction. |
In Apollo Server 4 we still don't call requestDidStart if context creation fails; that's because the GraphQLRequestContext argument to the plugin already has the |
The linked contextCreationDidFail example is inadequate, because it only shows a call to console.log rather than something practical like, for example, customizing the error response with error codes or i18n messaging. It would be nice if there were a single, predictable, stable, normal-looking, not-buggy and not-changing-with-each-new-version hook mechanism with a practical, not-wordy, not-meandering and complete example |
If an error is thrown during context creation the
requestDidStart
hook is not called. As a result, usingdidEncounterErrors
is not possible for those errors.Note:
formatError
function is calledThe text was updated successfully, but these errors were encountered: