const { ApolloServer } = require('apollo-server-micro')

const { schema } = require('./schema')
const { createErrorFormatter, sentryIgnoreErrors } = require('./errors')

module.exports = function createHandler(options) {
  let Sentry

  if (options.sentryDsn) {
    Sentry = require('@sentry/node')
    Sentry.init({
      dsn: options.sentryDsn,
      release: options.release,
      environment: process.env.NODE_ENV,
      ignoreErrors: sentryIgnoreErrors,
      onFatalError(error) {
        console.error(error, error.response)
      },
      debug: true,
    })
  }

  const formatError = createErrorFormatter(Sentry)
  const apolloServer = new ApolloServer({ schema, formatError })

  return apolloServer.createHandler({ path: '/' })
}

const { ApolloServer } = require('apollo-server-micro')

const { schema } = require('./schema')
const { createErrorFormatter, sentryIgnoreErrors } = require('./errors')

module.exports = function createHandler(options) {
  let Sentry

  if (options.sentryDsn) {
    Sentry = require('@sentry/node')
    Sentry.init({
      dsn: options.sentryDsn,
      release: options.release,
      environment: process.env.NODE_ENV,
      ignoreErrors: sentryIgnoreErrors,
      onFatalError(error) {
        console.error(error, error.response)
      },
      debug: process.env.DEBUG_SENTRY == 'true',
    })
  }

  const formatError = createErrorFormatter(Sentry)
  const apolloServer = new ApolloServer({ schema, formatError })

  return apolloServer.createHandler({ path: '/' })
}

Make sentry debug controllable with env variable
fix: Make sentry debug controllable with env variable

DEBUG_SENTRY=true will enable it.
