Send errors captured by graphql to sentry, bugsnag or similar
npm i graphql-notify-errors
const { formatError, GraphQLError } = require('graphql')
const express = require('express')
const Raven = require('raven')
const NotifyErrors = require('graphql-notify-errors')
Raven.config(process.env.SENTRY_DSN).install()
const filter = err => !(err instanceof GraphQLError)
const options = {
formatError,
filter,
notify: Raven.captureException
}
const notifyErrors = new NotifyErrors(options)
const app = express()
app.use('/graphql', graphqlExpress(req => {
return {
schema,
context: { req },
formatError: err => notifyErrors.formatError(err)
}
})
)