Skip to content

Commit

Permalink
Support graphql v16.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydenseric committed Nov 3, 2021
1 parent f0c4aff commit d420e34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Updated Node.js support to `^12.20.0 || ^14.13.1 || >= 16.0.0`.
- Updated dev dependencies, some of which require newer Node.js versions than previously supported.
- Updated the [`graphql`](https://npm.im/graphql) peer dependency to `^16.0.0`.
- Updated the `errorHandler` Koa middleware to avoid the `formatError` function deprecated in [`graphql`](https://npm.im/graphql) v16, using the new `GraphQLError.toJSON` method.

### Patch

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"node": "^12.20.0 || ^14.13.1 || >= 16.0.0"
},
"peerDependencies": {
"graphql": "0.13.1 - 15"
"graphql": "^16.0.0"
},
"dependencies": {
"http-errors": "^1.8.0",
Expand All @@ -50,7 +50,7 @@
"eslint-plugin-jsdoc": "^36.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"graphql": "^15.0.0",
"graphql": "^16.0.1",
"jsdoc-md": "^11.0.2",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
Expand Down
14 changes: 11 additions & 3 deletions public/errorHandler.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { formatError } from 'graphql';
import createHttpError from 'http-errors';

/**
Expand Down Expand Up @@ -45,7 +44,7 @@ export default function errorHandler() {
// Error contains GraphQL query validation or execution errors.

ctx.response.body.errors = error.graphqlErrors.map((graphqlError) => {
const formattedError = formatError(graphqlError);
const formattedError = graphqlError.toJSON();

if (
// Originally thrown in resolvers (not a GraphQL validation error).
Expand Down Expand Up @@ -87,7 +86,16 @@ export default function errorHandler() {
httpError.extensions = error.extensions;
}

ctx.response.body.errors = [formatError(httpError)];
const formattedError = {
message: httpError.message,
locations: httpError.locations,
path: httpError.path,
};

if (httpError.extensions)
formattedError.extensions = httpError.extensions;

ctx.response.body.errors = [formattedError];
ctx.response.status = httpError.status;
}

Expand Down

0 comments on commit d420e34

Please sign in to comment.