question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`didEncounterErrors` is not triggered when an error occurs in `context` creation.

See original GitHub issue

Bug

@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:closed
  • Created 4 years ago
  • Reactions:23
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
spencerwilsoncommented, Mar 31, 2021

Want to offer a use case:

If you have error-prone code in your context function

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.

9reactions
abernixcommented, Aug 30, 2019

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, the requestContext has a property on it called context, which is the actual context that the end-user creates within the context 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found