`didEncounterErrors` is not triggered when an error occurs in `context` creation.
See original GitHub issueBug
@abernix edits: The didEncounterErrors
life-cycle hook is not invoked when errors occur within context creation. That shouldn’t be the case!
Original feature request
As of version 2.9.0, there is no lifecycle event to handle manually errors encountered in the context creation process.
Suggestion:
const server = new ApolloServer({
context: () => { throw new Error('Ouch!') },
plugins: [
{
requestDidStart: () => ({
contextCreationDidFail: (error) => {
// do something here?
},
})
},
],
})
Issue Analytics
- State:
- Created 4 years ago
- Reactions:23
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Apollo Server plugin event reference
This hook is called when any execution errors are encountered after the initial payload is sent; didEncounterErrors is not called in this case....
Read more >useMutation hook error not corresponding with thrown ...
You can't throw an error in your context function. I'd suggest throwing an AuthenticationError (from 'apollo-server-errors' by the way.
Read more >Handling GraphQL Errors Using Sentry
In this case, we'll hook into the didEncounterErrors event our GraphQL server exposes and discard all errors right away that do not contain ......
Read more >GraphQL: Apollo Server Plugins in Typescript - Jeff Magnusson
In this case, parsingDidStart is not called for the request, because parsing does not occur. * @param context 'metrics' | 'source'. */. public ......
Read more >A Deep Dive on Apollo Data Sources
If a new database comes out, we'll first need to write a parent ... This class overrides didEncounterError to use its own error-reporting ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Want to offer a use case:
We do! In fact, it was inspired by the guidance in “API-wide authentication”. Our GraphQL API serves only confidential data and privileged mutations, so denying all requests that lack valid authentication is appealing to us.
The naming is a bit confusing but
requestContext
is representative of Apollo Server (the framework’s) context, not the user’s context. Put another way, therequestContext
has a property on it calledcontext
, which is the actual context that the end-user creates within thecontext
function.To me, it sounds like a bug that
didEnounterErrors
is not invoked when there is a user-context creation error, and it seems that we should consider addressing that. Therefore, I’ve adjusted this feature request to an issue, accordingly.