question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Whole query fails when one subquery fails

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ccjaracommented, Jan 15, 2020

For anyone else stumbling onto this issue: make sure you pass the nullable option into your resolver decorators. As nullable: 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):

If an error was encountered during the execution that prevented a valid response, the data entry in the response should be null.

Apollo does the only correct (spec compliant) thing here.

Fix:

-@Query(returns => Recipe)
+@Query(returns => Recipe, { nullable: true })

@khayalan-mathew: This also fixes the problem in your reproduction repository.

0reactions
lock[bot]commented, Apr 25, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found