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.

devops
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 is a named export, not default.

import { createError } from 'apollo-errors'

Both ESM and CJS are supported. CJS require works but named imports are preferred for tree-shaking.

import { formatError } 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.

import { isInstance } from 'apollo-errors'

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 footguns
gotchaisInstance expects the originalError property of a GraphQLError, not the error itself when used in formatError.
deprecatedThe package is no longer actively maintained. Apollo Server has built-in error handling with ApolloError class since apollo-server v2.
gotchaThe formatError function only formats known ApolloErrors; unknown errors are passed through unchanged. This may mask unexpected errors.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
12 hits · last 30 days
gptbot
3
bytedance
2
ahrefsbot
1
Resources