Last active
February 10, 2019 15:45
-
-
Save philsch/3e3e1362a7aa141ae24880bc28b4464b to your computer and use it in GitHub Desktop.
Blogpost: GraphQL Apollo Server errors and the request context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ApolloServer, SyntaxError, UserInputError, AuthenticationError, ForbiddenError} from 'apollo-server-express'; | |
import {GraphQLErrorTrackingExtension} from 'graphql-error-tracking-extension'; | |
import {ErrorReporting} from '@google-cloud/error-reporting'; | |
const errorReporting = new ErrorReporting(); | |
const server = new ApolloServer({ | |
schema, | |
extensions: [() => new GraphQLErrorTrackingExtension({ | |
maskHeaders: ['x-forwarded-for', 'authorization'], | |
revealErrorTypes: [SyntaxError, UserInputError, AuthenticationError, ForbiddenError], | |
onUnrevealedError: (err, originalError) => { | |
if (originalError) { | |
errorReporting.report(err.originalError.stack); | |
} else { | |
errorReporting.report(err.stack); | |
} | |
} | |
})], | |
context: ({req}) => ({ | |
request: req | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment