Skip to content

Commit 54df48d

Browse files
IvanGoncharovleebyron
authored andcommitted
Add optional 'extensions' entry to errors (#407)
* Add optional 'extensions' entry to errors * Some minor formatting changes * Specify additional entry to errors * Update Section 7 -- Response.md * Update Section 7 -- Response.md
1 parent 55fa43e commit 54df48d

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

spec/Section 7 -- Response.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,45 @@ be the same:
248248
}
249249
```
250250

251-
GraphQL servers may provide additional entries to error as they choose to
252-
produce more helpful or machine-readable errors, however future versions of the
253-
spec may describe additional entries to errors.
251+
GraphQL services may provide an additional entry to errors with key `extensions`.
252+
This entry, if set, must have a map as its value. This entry is reserved for
253+
implementors to add additional information to errors however they see fit, and
254+
there are no additional restrictions on its contents.
255+
256+
```json example
257+
{
258+
"errors": [
259+
{
260+
"message": "Name for character with ID 1002 could not be fetched.",
261+
"locations": [ { "line": 6, "column": 7 } ],
262+
"path": [ "hero", "heroFriends", 1, "name" ],
263+
"extensions": {
264+
"code": "CAN_NOT_FETCH_BY_ID",
265+
"timestamp": "Fri Feb 9 14:33:09 UTC 2018"
266+
}
267+
}
268+
]
269+
}
270+
```
271+
272+
GraphQL services should not provide any additional entries to the error format
273+
since they could conflict with additional entries that may be added in future
274+
versions of this specification.
275+
276+
> Note: Previous versions of this spec did not describe the `extensions` entry
277+
> for error formatting. While non-specified entries are not violations, they are
278+
> still discouraged.
279+
280+
```json counter-example
281+
{
282+
"errors": [
283+
{
284+
"message": "Name for character with ID 1002 could not be fetched.",
285+
"locations": [ { "line": 6, "column": 7 } ],
286+
"path": [ "hero", "heroFriends", 1, "name" ]
287+
"code": "CAN_NOT_FETCH_BY_ID",
288+
"timestamp": "Fri Feb 9 14:33:09 UTC 2018"
289+
}
290+
]
291+
}
292+
```

0 commit comments

Comments
 (0)