graphql-middleware-sentry
raw JSON → 3.2.1 verified Sat Apr 25 auth: no javascript
GraphQL Middleware plugin for Sentry error tracking (v3.2.1). Integrates Sentry with GraphQL middleware to automatically capture resolver errors. Key features: configurable withScope for enriching Sentry events, reportError filter for custom errors, support for forwarded or captured errors. Requires @sentry/node (^5.2.0), graphql (^0.11-14), and graphql-middleware (^2-4). Ships TypeScript types. Last released in 2019; actively maintained.
Common errors
error Cannot find module 'graphql-middleware-sentry' ↓
cause Package not installed or wrong peer dependencies.
fix
Run
npm install graphql-middleware-sentry @sentry/node graphql graphql-middleware. error TypeError: sentry is not a function ↓
cause Using default import instead of named import.
fix
Use
import { sentry } from 'graphql-middleware-sentry' instead of import sentry from .... error Property 'config' is missing in type '{ dsn: string; }' ↓
cause Passing `dsn` as top-level option in v3.
fix
Set
config: { dsn: '...' } instead of dsn: '...'. Warnings
breaking v3.0.0 removed the `dsn` configuration option; use `config.dsn` instead. ↓
fix Pass DSN via `config: { dsn: '...' }` instead of top-level `dsn`.
breaking v2.0.0 migrated from `raven` to `@sentry/node`. Old raven-based configs are invalid. ↓
fix Replace `raven` with `@sentry/node` and use `Sentry.init(config)` before passing sentryInstance.
deprecated The `reportError` option requires filtering by message string or instance; no built-in filtering is provided. ↓
fix Implement a custom `reportError` function as shown in the README.
gotcha If both `sentryInstance` and `config` are provided, the plugin will use the instance and ignore config. ↓
fix Provide only one of `sentryInstance` or `config`; if both given, only `sentryInstance` takes effect.
Install
npm install graphql-middleware-sentry yarn add graphql-middleware-sentry pnpm add graphql-middleware-sentry Imports
- sentry wrong
import sentry from 'graphql-middleware-sentry'correctimport { sentry } from 'graphql-middleware-sentry' - Options wrong
const { Options } = require('graphql-middleware-sentry')correctimport type { Options } from 'graphql-middleware-sentry' - ExceptionScope wrong
import { ExceptionScope } from 'graphql-middleware-sentry'correctimport type { ExceptionScope } from 'graphql-middleware-sentry'
Quickstart
import { GraphQLServer } from 'graphql-yoga';
import { sentry } from 'graphql-middleware-sentry';
const typeDefs = `
type Query {
hello: String!
bug: String!
}
`;
const resolvers = {
Query: {
hello: () => `Hey there!`,
bug: () => { throw new Error(`Many bugs!`); }
}
};
const sentryMiddleware = sentry({
config: {
dsn: process.env.SENTRY_DSN ?? '',
environment: process.env.NODE_ENV
},
withScope: (scope, error, context) => {
scope.setUser({ id: context.authorization.userId });
scope.setExtra('body', context.request.body);
},
});
const server = new GraphQLServer({
typeDefs,
resolvers,
middlewares: [sentryMiddleware]
});
server.start(() => console.log('Server running on http://localhost:4000'));