-
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
How to implement provide context on global error handlers #1681
Comments
@theduyetmai, if you use the const { ApolloServer } = require('apollo-server')
import { GraphQLExtension } from 'graphql-extensions'
class MyErrorTrackingExtension extends GraphQLExtension {
willSendResponse(o) {
const { context, graphqlResponse } = o
context.trackErrors(graphqlResponse.errors)
return o
}
// Other lifecycle methods include
// requestDidStart
// parsingDidStart
// validationDidStart
// executionDidStart
// willSendResponse
}
const server = new ApolloServer({
typeDefs,
resolvers,
extensions: [() => new MyErrorTrackingExtension()],
context({ req }) {
return {
req,
trackErrors(errors) {
// Track the errors
},
}
},
})
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
}) |
Thank you so much |
on which version of apollo-server it's supposed to work? I have 2.1.0, but still have context being undefined @Whoaa512 |
Bumping this issue, the fix brought in to v2.0.8 does seem like it would be the fix to allow for the context to be accessible from within the |
I just check the below PR but still do not know how to implement. Any else can help me?
#1343
Thank you so much
The text was updated successfully, but these errors were encountered: