Skip to content

Commit 1793f24

Browse files
committed
Added resolver-returned value to the error object, plus further documentation on expected error fields (graphql#590)
1 parent d634e41 commit 1793f24

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ The `graphqlHTTP` function accepts the following options:
118118
errors produced by fulfilling a GraphQL operation. If no function is
119119
provided, GraphQL's default spec-compliant [`formatError`][] function will be used.
120120

121+
Although the fields on the error provided to this function may vary (based on the error type), they will typically include:
122+
* **message:** the error message
123+
* **locations:** the location(s) in the Javascript code where the error ocurred
124+
* **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)
125+
* **result:** the value which was returned by the resolver (if any)
126+
121127
- **`customParseFn`**: An optional function which will be used to create a document
122128
instead of the default `parse` from `graphql-js`.
123129

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ function graphqlHTTP(options: Options): Middleware {
368368
}
369369
// Format any encountered errors.
370370
if (result && result.errors) {
371+
(result: any).errors = result.errors.map(err => ({...err, result: result.data}));
371372
(result: any).errors = result.errors.map(formatErrorFn);
372373
}
373374

0 commit comments

Comments
 (0)