Graphql errors: Difference between revisions
From wikinotes
(Created page with "There are two possible replies for a graphql request. * (success) a json object with the key <code>data</code> * (failure) a json list with the key <code>errors</code> data...") |
No edit summary |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Documentation = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| spec(2018): error format || https://spec.graphql.org/June2018/#sec-Errors | |||
|- | |||
|} | |||
</blockquote><!-- Documentation --> | |||
= Basics = | |||
<blockquote> | |||
There are two possible replies for a graphql request. | There are two possible replies for a graphql request. | ||
<syntaxhighlight lang="javascript"> | |||
// success (a json object with the key 'data') | |||
{"data": {"name": "foo", "id": 1} | |||
// failure (a json list with the key 'errors') | |||
{ | |||
"errors": [ | |||
{ | |||
"message": "Name for character with ID 1002 could not be fetched.", // <--- graphql spec keys | |||
"locations": [ { "line": 6, "column": 7 } ], | |||
"path": [ "hero", "heroFriends", 1, "name" ], | |||
"extensions": { // <-- library/application specific keys | |||
"code": "CAN_NOT_FETCH_BY_ID", | |||
"timestamp": "Fri Feb 9 14:33:09 UTC 2018" | |||
} | |||
} | |||
] | |||
} | |||
</syntaxhighlight> | |||
Note that the <code>extensions</code> key was introduced to the spec in 2018. | |||
</blockquote><!-- Basics --> |
Latest revision as of 14:51, 4 September 2021
Documentation
spec(2018): error format https://spec.graphql.org/June2018/#sec-Errors
Basics
There are two possible replies for a graphql request.
// success (a json object with the key 'data') {"data": {"name": "foo", "id": 1} // failure (a json list with the key 'errors') { "errors": [ { "message": "Name for character with ID 1002 could not be fetched.", // <--- graphql spec keys "locations": [ { "line": 6, "column": 7 } ], "path": [ "hero", "heroFriends", 1, "name" ], "extensions": { // <-- library/application specific keys "code": "CAN_NOT_FETCH_BY_ID", "timestamp": "Fri Feb 9 14:33:09 UTC 2018" } } ] }Note that the
extensions
key was introduced to the spec in 2018.