apollo-error
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Apollo Error

Custom payload in Apollo GraphQL server.

Usage

Install via npm

npm install apollo-error

Bind with Apollo Server

Showing example for Express below.

import express from 'express';
import bodyParser from 'body-parser';
import { graphqlExpress } from 'apollo-server-express';
import { formatError } from 'apollo-error';
 
import schema from './graphql/schema';
 
const app = express();
 
app.use('/graphql', bodyParser.json(), graphqlExpress({
    formatError,
    schema
}));
 
app.listen(3000);

Throw ApolloError

throw new ApolloError(message, {
    /* your custom payload here */
    foo: 'bar',
    ...
});

Response handling

You can access the custom payload in your response handler like the following.

if(response.errors) {
    const myErrorMessage = response.errors[0].message;
    const myErrorExtras = response.errors[0].data;
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    15
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    15
  • 1.0.1
    0
  • 1.0.0
    1

Package Sidebar

Install

npm i apollo-error

Weekly Downloads

16

Version

1.0.2

License

MIT

Last publish

Collaborators

  • jaibatrik