Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abacritt/apollo-error
Custom payload in Apollo GraphQL server.
https://github.com/abacritt/apollo-error
apollo-server apollo-server-express apollographql
Last synced: about 2 months ago
JSON representation
Custom payload in Apollo GraphQL server.
- Host: GitHub
- URL: https://github.com/abacritt/apollo-error
- Owner: abacritt
- License: mit
- Created: 2018-02-03T14:11:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-04T11:01:58.000Z (almost 7 years ago)
- Last Synced: 2024-10-31T18:05:35.448Z (about 2 months ago)
- Topics: apollo-server, apollo-server-express, apollographql
- Language: TypeScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Apollo Error
Custom payload in Apollo GraphQL server.
## Usage
### Install via npm
```sh
npm install apollo-error
```### Bind with Apollo Server
Showing example for Express below.
```javascript
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
```javascript
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.
```javascript
if(response.errors) {
const myErrorMessage = response.errors[0].message;
const myErrorExtras = response.errors[0].data;
}
```