I have a question concering how the response of a GraphQL query/mutation should look like in each of the following cases:
I'm not sure the latter is even possible, but I seem to remember reading somewhere that it could happen. E.g. in the case of multiple mutations, let's say two, where each mutation is processed sequentially. I think case #3 from above could happen if the first mutation is fine, but an error occurs during the execution of the second, but I'm not sure.
Anyway, how should the responses look like? Like the ones below? (Examples in JSON, where each corrensponds to the cases from before.) Or are there other ways that are more idiomatic? Perhaps Relay provide some guidelines as to how it should look like? I couldn't find any good resources for this.
1:
{
"data": {
...
}
}
2:
{
"errors": [
{
...
},
...
]
}
3:
{
"data": {
...
},
"errors": [
{
...
},
...
]
}
Thanks.
Yes, your sample responses look right to me. Here's a more detailed example of "case 3".
query MyQuery {
viewer {
articles(first: 1) {
edges {
node {
title
tags # we'll introduce an error in the schema here
}
}
}
}
}
{
"data": {
"viewer": {
"articles": {
"edges": [
{
"node": {
"title": "Sample article title",
"tags": null
}
}
]
}
}
},
"errors": [
{
"message": "Cannot read property 'bar' of undefined",
"locations": [
{
"line": 7,
"column": 11
}
]
}
]
}