Whole query fails when one subquery fails
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When sending multiple queries at once like
query {
getReservationId(id: "1") {
id
}
getReservationById(id: "2") {
id
}
}
and one of them fails (because of a guard for example), the query returns null as data, regardless even if the second one was successful.
Current output
{
"errors": [
{
"message": {
"statusCode": 401,
"error": "Unauthorized",
"message": "Not sufficient scopes provided, scopes required: create:project,fail"
},
"locations": [
{
"line": 5,
"column": 3
}
],
"path": [
"getReservationById"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"response": {
"statusCode": 401,
"error": "Unauthorized",
"message": "Not sufficient scopes provided, scopes required: create:project,fail"
},
"status": 401,
"message": {
"statusCode": 401,
"error": "Unauthorized",
"message": "Not sufficient scopes provided, scopes required: create:project,fail"
},
"stacktrace": [
"Error: [object Object]",
...
]
}
}
}
],
"data": null
}
Expected behavior
Returning data something like this
"errors" : [...]
"data": {
"getReservationId": {
"id": "1"
},
"getReservationById": null
}
Minimal reproduction of the problem with instructions
Example repo based on the type-graphql example provided in the nestjs main repository
Error occurs when using following queries
{
recipe(id: "Test") {
description
}
}
Works perfectly fine
{
recipe(id: "Test") {
description
}
recipes(skip: 0) {
description
}
}
return data: null, even though the recipe query should succeed
What is the motivation / use case for changing the behavior?
GraphQL biggest advantage is combining queries dynamically, this issue restricts this ability heavily
Environment
Nest version: 6.2.0
For Tooling issues:
- Node version: 11.15.0
- Platform: Linux
Others:
apollo-server-express: 2.5.0
graphql: 14.3.0
@nestjs/graphql: 6.2.1
@nestjs/common: 6.2.0
graphql-tools: 4.0.4
type-graphql: 0.17.4,
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Query returning Wrong data even inner Subquery has syntax ...
If a column is referenced in a subquery that does not exist in the table referenced by the subquery's FROM clause, but exists...
Read more >What happens if the sub-query on an IN operator fails?
So the subquery for the IN operator fails if you run it. However, if I execute the query as a whole, it always...
Read more >MySQL 5.7 Reference Manual :: 13.2.10.9 Subquery Errors
For transactional storage engines, the failure of a subquery causes the entire statement to fail. For nontransactional storage engines, data modifications made ...
Read more >A query joining on subquery without alias fails with the error ...
The reason for the failure is because a subquery without an alias has a default alias of values. Therefore, both subqueries will have...
Read more >How to deal with subqueries in SQL with this error
... for a SELECT that is part of an expression". What is the problem? I have selected a single item to be pulled...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone else stumbling onto this issue: make sure you pass the
nullable
option into your resolver decorators. Asnullable: false
is the default setting, this will generate a schema where a return value is required. If you compose multiple queries and one of them fails, you would return a document where the subquery is required by the schema to return non-null data, but doesn’t actually have any data, since the query failed.From the GraphQL specification (Jun 2018, most recent as of writing):
Apollo does the only correct (spec compliant) thing here.
Fix:
@khayalan-mathew: This also fixes the problem in your reproduction repository.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.