-
Notifications
You must be signed in to change notification settings - Fork 660
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
Feature request: Resilient Parsing #2520
Comments
Thanks for the detailed feature request! A few early thoughts:
Also, I've been thinking about changing the way we parse the json. We currently parse in 2 steps, first to a |
Thanks for the questions!
Correct, the error bubbling spec I linked is for the server. But I feel like this part of the client is an implementation choice, and it seems like giving developers the ability to leverage GraphQLs nullability/error system (which the server spec demonstrates there is a sane model for) to have more resilient old clients seems great. We could make this behavior opt in / opt out.
Yes. I have been playing around with an implementation and it needs to make sure the normalized cache stays consistent. But it seems reasonable to just put a
Good point - I think with a specific enough name I would be okay starting off with just the root errors, but our hypothesis is that for some large aggregate queries, it will be helpful to know at any arbitrary point if there were parsing errors, and I can think of a good design for the root errors that is not stringly typed. |
Separately, I would love to see us switch to a streaming parsing model. I do believe it would make a meaningful difference in parsing performance. |
Follow up issue there for the streaming parser: #2523 |
Anyone reading this might be interested in
But it could be modified to handle parsing errors (such as |
Feature Request: Resilient Parsing
The graphql spec introduces the concept of error bubbling, where partial errors are allowed by bubbling up to the first element that is nullable.
Protect against backwards incompatible changes
If a server changes a field from being non-null to nullable existing clients that have already been shipped would completely break, even if the client appropriately handles nullability at an object higher up in the response.
Implementation
When parsing object types catch errors and replace the parsed value with null. This achieves a bubble effect where the error will propagate up the parse chain until we hit a nullable object.
When parsing lists a null value is read, if the list is of non-null types the entire list should resolve to null and bubble up the error.
We could consider doing the same thing for custom scalar types, which would allow faulty custom scalar logic to resolve to null for a nullable custom scalar type.
Errors are collected in a partial error response object on the root operation, next to the standard graphql errors:
The ParseError object should form a chain of failures, if the error included multiple bubbled up response. Like the standard Error, this ParseError should include in a location in the query where the failure occurred.
In addition to surfacing the errors at the RootResponse we should be able opt-into generating an errors property on any object element in the response via a generateErrorAccessor directive. This seems possible by having the ErrorCollector track an “ongoing” error object, that “resolves” when the response reader is able to set a value to null.
Examples:
Simple:
object1 resolves to null
error present in data
Object bubble:
Non-null List:
List resolves to null
Nullable list
List contains null element for object 2
Other uses: Allow client “required” directive
An often requested client directive is the ability to mark a field on the client as “required” transforming it from nullable to non-null. However, as in the backwards incompatible case, if this requirement fails, it would be ideal to allow to response to still partially succeed.
The text was updated successfully, but these errors were encountered: