Registry / devops / graphql-apollo-errors

graphql-apollo-errors

JSON →
library2.0.3jsnpmunverified

Customizable GraphQL/Apollo error handling library (v2.0.3). Allows you to control error formatting, hook into error processing (original, processed, final), hide sensitive data, whitelist public data paths, and transform non-Boom errors. Integrates with hapi/boom for structured error payloads. Fully tested with 100% coverage. Active development, weekly releases.

npm install graphql-apollo-errors
INSTALL
IMPORT
SIG · GRAPHQL-APOLLO-ERR
G
graphql-apollo-errors
devopsjavascriptv2.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

formatErrorGenerator
import { formatErrorGenerator } from 'graphql-apollo-errors'
const formatErrorGenerator = require('graphql-apollo-errors');
Library is CJS, but for consistency use named import. CommonJS require returns an object, not the function directly.
default
import graphqlApolloErrors from 'graphql-apollo-errors'
const graphqlApolloErrors = require('graphql-apollo-errors').default
No default export exists. Use named import instead.
createError
import { createError } from 'graphql-apollo-errors'
createError is a named export for creating custom errors.

Setup Apollo Server with custom error formatting using graphql-apollo-errors, including hooks and data path whitelisting.

import express from 'express'; import bodyParser from 'body-parser'; import { graphqlExpress } from 'apollo-server-express'; import { formatErrorGenerator } from 'graphql-apollo-errors'; import Schema from './schema'; const formatError = formatErrorGenerator({ logger: console, publicDataPath: 'public', showLocations: true, showPath: true, hideSensitiveData: false, hooks: { onOriginalError: (err) => console.log('Original:', err.message), onProcessedError: (err) => console.log('Processed:', err.message), onFinalError: (err) => console.log('Final:', err.message), }, nonBoomTransformer: (nonBoomError) => SevenBoom.badRequest(nonBoomError.message), }); const app = express(); app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: Schema, formatError })); app.listen(4000, () => console.log('Server running on 4000'));
Debug
Known issues
breakingv2 requires @hapi/boom (previously boom) as a peer dependency
fix
Install @hapi/boom: npm install @hapi/boom
affects: >=2.0.0
gotchaLibrary uses CJS; cannot be imported using ESM default import
fix
Use named imports: import { formatErrorGenerator } from 'graphql-apollo-errors'
affects: >=0.0.0
deprecatednonBoomTransformer option previously defaulted to throwing; now defaults to transforming to boom error
fix
Provide explicit nonBoomTransformer function or rely on new default behavior
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: formatErrorGenerator is not a function
Incorrect import: using default import on a CJS module
fix
Use named import: import { formatErrorGenerator } from 'graphql-apollo-errors'
Error: Cannot find module '@hapi/boom'
Missing peer dependency @hapi/boom
fix
Run: npm install @hapi/boom
GraphQLError: Expected a value of type "Object"
nonBoomTransformer returns a non-Boom error object
fix
Return a Boom error: nonBoomTransformer: (err) => SevenBoom.badImplementation(err)
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
@hapi/boomrequiredProvides structured error payloads and HTTP error classes
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-apollo-errors — npm install graphql-apollo-errors · libregistry