Registry / security / graphql-errors

graphql-errors

JSON →
library2.1.0jsnpmunverified

A utility library for masking internal error messages in GraphQL responses. Version 2.1.0 (stable) – low release cadence. Provides `maskErrors()` to intercept and replace error messages with a generic 'internal error' string, while logging the full error server-side for debugging. Differentiates from alternatives like `graphql-middleware` or `formatError` by operating directly on the schema with minimal configuration. Requires `graphql` >0.4.0 as a peer dependency.

npm install graphql-errors
INSTALL
IMPORT
SIG · GRAPHQL-ERRORS
G
graphql-errors
securityjavascriptv2.1.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.

maskErrors
import { maskErrors } from 'graphql-errors'
const maskErrors = require('graphql-errors').maskErrors
ESM or CJS both supported. CJS works too.
processSchema
import { processSchema } from 'graphql-errors'
Advanced usage to customize masking behavior.
default
import graphqlErrors from 'graphql-errors'
const graphqlErrors = require('graphql-errors')
Default export is an object containing maskErrors and processSchema.

Demonstrates masking a GraphQL schema to replace sensitive error messages.

import { maskErrors } from 'graphql-errors'; import { buildSchema } from 'graphql'; const schema = buildSchema(` type Query { test: String } `); const rootValue = { test: () => { throw new Error('secret message'); } }; maskErrors(schema); // schema now masks errors schema._queryType.getFields().test.resolve = rootValue.test; console.log(schema._queryType.getFields().test.resolve()); // throws but error message is replaced
Debug
Known issues
gotchamaskErrors mutates the schema in place – does not return a new schema.
fix
Ensure you call maskErrors before using the schema in a server.
affects: >=1.0.0
deprecatedDeprecated in favor of formatError in graphql-js or graphql-middleware.
fix
Consider using graphql-js's formatError option or a middleware library.
affects: >=2.0.0
gotchaOnly masks errors from resolvers; validation errors still exposed.
fix
Separately handle validation errors or use a custom formatError function.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read property 'getFields' of undefined
maskErrors called before schema has query/mutation types defined.
fix
Ensure schema is fully built and has query type before calling maskErrors.
Error: maskErrors expects a GraphQLSchema object
Passed a non-schema object (e.g., schema string) to maskErrors.
fix
Convert schema to GraphQLSchema using buildSchema or GraphQLSchema constructor first.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency: required for schema manipulation
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
graphql-errors — npm install graphql-errors · libregistry