-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[RFC] Add error path to response #187
Conversation
Just like it is helpful to know the location in the query associated with an error, it's helpful to know the location in the response.
I think the simpler way of addressing that concern would be to omit the field in the result if there was an error rather. Also, errors in non-null type fields could just not be propagated such that missing data could be used as an indicator of where the errors occur. However, even with that change your proposal would be useful to associate errors with specific elements in an array. |
There are a few reasons this is better than just returning
You can imagine if you are rendering a huge page with one GraphQL query, it would be nice to show any relevant errors in the correct part of the UI, rather than at the top level. Of course, it is possible to build a custom error tagging system for this, but it would be much nicer if there was this relatively small built-in thing, especially since we already have line and column position for the error. |
It sounds like you are using top-level errors as a way to display user input errors, which isn't the intended purpose for those errors. The top-level errors entry was meant to have error messages that are intended for the developer. This is mentioned in the graphql spec in the Errors section:
This has been further clarified in a graphql spec issue (#117 (comment)) |
No, I'm talking about a situation where a fetch to a backend API failed, causing that part of the GraphQL query to return If the GraphQL |
Refreshing this RFC since I think it's really important to get included. This is critical information to let clients deduce which errors correspond to which fields. |
I think the spec addition needs to be a little more descriptive. Definitely it needs to include some examples and deeper explanation of the expected behavior for some of the edge cases:
|
Following up on @leebyron's comments: graphql#187 (comment)
Going to close and reopen this to have a better branch name than |
* Add error path to response Just like it is helpful to know the location in the query associated with an error, it's helpful to know the location in the response. * Updates to error result format Following up on @leebyron's comments: #187 (comment) * Improve organization * Clarify why this feature is useful * Fix typo * Fix index in error path * Add example for non-null field * Formatting, and change array to list * Change "should" to "must" * Clarify what's required when data is null. `{"data": null}` is a legal response when loading a top level field of a nullable type that intentionally returned null. Updating this language to ensure it remains legal. * Move "errors" to top field. New convention for highlighting errors * Another instance of errors over data
* Add error path to response Just like it is helpful to know the location in the query associated with an error, it's helpful to know the location in the response. * Updates to error result format Following up on @leebyron's comments: graphql#187 (comment) * Improve organization * Clarify why this feature is useful * Fix typo * Fix index in error path * Add example for non-null field * Formatting, and change array to list * Change "should" to "must" * Clarify what's required when data is null. `{"data": null}` is a legal response when loading a top level field of a nullable type that intentionally returned null. Updating this language to ensure it remains legal. * Move "errors" to top field. New convention for highlighting errors * Another instance of errors over data
Just an idea for discussion - adding the path to the response, like this implementation in
graphql-js
:Just like it is helpful to know the location in the query associated with an error, it's helpful to know the location in the response.
This is already implemented in errors thrown from resolvers in
graphql-js
, so it would just be a matter of having the right error formatting to include that information.This would be extremely helpful to differentiate when a field is
null
in the result because the result was actuallynull
, and when it is because of a runtime error in the resolver.