Skip to content

Commit

Permalink
Added resolver-returned value to the error object, plus further docum…
Browse files Browse the repository at this point in the history
…entation on expected error fields (graphql#590)
  • Loading branch information
machineghost committed Mar 18, 2020
1 parent d634e41 commit 1793f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ The `graphqlHTTP` function accepts the following options:
errors produced by fulfilling a GraphQL operation. If no function is
provided, GraphQL's default spec-compliant [`formatError`][] function will be used.

Although the fields on the error provided to this function may vary (based on the error type), they will typically include:
* **message:** the error message
* **locations:** the location(s) in the Javascript code where the error ocurred
* **path:** the path within the returned results where the error occurred (eg. in a schema violation error, the path to the part of the results that violated the schema)
* **result:** the value which was returned by the resolver (if any)

- **`customParseFn`**: An optional function which will be used to create a document
instead of the default `parse` from `graphql-js`.

Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ function graphqlHTTP(options: Options): Middleware {
}
// Format any encountered errors.
if (result && result.errors) {
(result: any).errors = result.errors.map(err => ({...err, result: result.data}));
(result: any).errors = result.errors.map(formatErrorFn);
}

Expand Down

0 comments on commit 1793f24

Please sign in to comment.