Registry / devops / apollo-errors

apollo-errors

JSON →
library1.9.0jsnpmunverified

apollo-errors v1.9.0 is a utility for creating machine-readable custom GraphQL errors for use with Apollo Server. It allows defining typed errors with structured data and internal logging data that can be separated from the client-facing response. The package provides createError() to define error classes, formatError() for server error formatting, and isInstance() for checking error types. It ships TypeScript definitions. The project appears to be in maintenance mode with no recent updates. Compared to alternatives like graphql-errors, it offers explicit data and internalData separation and built-in formatting for Apollo Server.

npm install apollo-errors
INSTALL
IMPORT
SIG · APOLLO-ERRORS
A
apollo-errors
devopsjavascriptv1.9.0
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.

createError
import { createError } from 'apollo-errors'
import createError from 'apollo-errors'
createError is a named export, not default.
formatError
import { formatError } from 'apollo-errors'
const formatError = require('apollo-errors').formatError
Both ESM and CJS are supported. CJS require works but named imports are preferred for tree-shaking.
isInstance
import { isInstance } from 'apollo-errors'
import { isApolloErrorInstance } from 'apollo-errors'
The function is exported as isInstance, not isApolloErrorInstance (which is used in documentation examples but not the actual export). Check your imports.

Shows how to define a custom error, configure Apollo Server to use formatError, and log internal data.

import { createError, formatError, isInstance } from 'apollo-errors'; import { ApolloServer } from 'apollo-server'; const MyError = createError('MyError', { message: 'Custom error occurred' }); const server = new ApolloServer({ typeDefs: ` type Query { test: String } `, resolvers: { Query: { test: () => { throw new MyError({ data: { detail: 'something broke' } }); }, }, }, formatError: (err) => { if (isInstance(err.originalError)) { // log internalData server-side console.log('Internal:', err.originalError.internalData); return formatError(err); } return err; }, }); server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
Debug
Known issues
gotchaisInstance expects the originalError property of a GraphQLError, not the error itself when used in formatError.
fix
Use isInstance(err.originalError) instead of isInstance(err) inside formatError.
affects: >=1.0.0
deprecatedThe package is no longer actively maintained. Apollo Server has built-in error handling with ApolloError class since apollo-server v2.
fix
Consider using ApolloServer's built-in ApolloError from 'apollo-server-errors' or 'graphql-tools' for official support.
affects: >=1.0.0
gotchaThe formatError function only formats known ApolloErrors; unknown errors are passed through unchanged. This may mask unexpected errors.
fix
Always handle non-ApolloErrors explicitly in your custom formatter.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: createError is not a function
Default import instead of named import: import createError from 'apollo-errors'
fix
Use named import: import { createError } from 'apollo-errors'
UnhandledPromiseRejectionWarning: Error: Expected error to be an ApolloError
Passing a non-ApolloError to formatError without checking isInstance
fix
Check isInstance(err.originalError) before calling formatError inside your Apollo Server formatError function
Cannot find module 'apollo-errors'
Package not installed or missing from package.json
fix
Run npm install apollo-errors
Upgrade
Version history
1.9.0latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency; required for GraphQL error type compatibility
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
apollo-errors — npm install apollo-errors · libregistry