Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple queries / mutations in single request stop at first error #2418

Closed
MarcEspiard opened this issue Jun 29, 2023 · 3 comments
Closed
Labels
question Request for support or clarification

Comments

@MarcEspiard
Copy link

MarcEspiard commented Jun 29, 2023

Describe the bug

When submitting multiple queries or mutations in the same request, if an error is thrown by one of the queries (validation error etc..) processing will stop and return the errors without returning the queries / mutations already processed.
As execution stops at the first error, it will not process any other query / mutation after the first error.

Expected behavior/Solution

All queries / mutations are processed, and a mix response of data and errors is returned.
From what I have read from other issues, the fact that Lighthouse always returns a 200 is to support this specific use case, when the request partially fails.

Steps to reproduce

  1. Query example:
    image
    In this example, the "validQuery" is processed (I can see the SQL queries being made and it goes through the @paginate directive)
    Then the invalidQuery triggers an error as it's over the items limit (expected).
    The output should have also returned a "data" entry with the results of "validQuery".

  2. Mutation Example:
    image
    "invite1" is correctly processed (I can see the SQL queries + job + email invitation sent)
    "invite2" has validation error (expected)
    "invite3" is NOT processed at all, execution stopped at "invite2" (not expected)

I would have expected all 3 mutations to be processed, with the response containing the data for invite 1 & 3 and the error for invite 2

Lighthouse Version
v6.10.0

php 8.2.5
Laravel 10.13

@spawnia spawnia added the question Request for support or clarification label Jun 29, 2023
@spawnia
Copy link
Collaborator

spawnia commented Jun 29, 2023

Lighthouse works as expected here, I added a test just to be sure: 2ecc00c.

Consider https://spec.graphql.org/draft/#sec-Handling-Field-Errors. GraphQL repsonses will always conform to what is promised in the schema. If a non-nullable field at any level of the query tree has an error, that entire level is invalidated and the error bubbles up to the next level. If you you already on the top level, you will get no data at all.

@MarcEspiard
Copy link
Author

Hey @spawnia, thanks for the clarification, I wasn't aware of that distinction, pretty new to GraphQL.

Quick question, changing the return types to nullable did indeed work on mutations but not for my queries example, is there a reason for that, other than nullable return types ?

@mowses
Copy link

mowses commented Jan 16, 2024

Sorry for commenting in a closed issue.

Using lighthouse v6, I would like to opt to make my mutations to stop if one of them fails. Is it possible to achieve such thing?

For example, this is an pseudo request a client is making:

mutation update_and_insert {
   updateRow {...}
   insertRow {...}
}

Both of these mutations are decorated with @field (resolver: "path/to/mutation@method")
The updateRow is prone to throw exceptions due to many factors. When it happen, I would like to prevent insertRow to insert new row in database.
Does anybody knows if it's possible to run both of mutations inside a "transaction block" without creating a third mutation just to wrap updateRow and insertRow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Request for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants