We are using GraphQL using apollo-server, we are trying to execute multiple queries in a single Query Operation as described below.
I expect that both queries should execute and provide their results.
query Operation1 {
getPosts: {
id
title
url
}
getBooks: {
id
title
}
}
Now in the above case, if both queries are successful, then we are getting results for both given below.
{
"data": {
"getPosts": [{
"id": "P1",
"title": "post1",
"url": "/blog/post1"
}],
"getBooks": [{
"id": "B1",
"title": "book1"
}]
}
}
But if in case any of query fails, the result is only represented as errors.
{
"data": {},
"errors": [
{
"message": "failure message",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"getBooks"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
]
}
I am not sure if this is the desired behavior because my expectation was as follows.
{
"data": {
"getPosts": [
{
"id": "P1",
"title": "post1",
"url": "/blog/post1"
}
],
"getBooks": {
"data": {},
"errors": [
{
"message": "failure message",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"getBooks"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR"
}
}
]
}
}
}
From the apollo docs: https://www.apollographql.com/docs/react/data/queries/#inspecting-error-states