-
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
error propagation considered harmful #719
Comments
Why not allow null in schema then? |
I think your observations are really just supporting the idiom and best practice that is fairly well established with GraphQL: default to nullable, and use non-null to explicitly opt in to error propagation behavior. I think you may also be confusing what is enforcing non-null: it isn't the client, but the server itself. If a schema says "the field In real-world schemas, fields may be null due to nonexistence, ephemeral errors, permission limits, or any other business logic that the client may or may not care about. To support this reality, the GraphQL type system itself defaults types to null, quite unlike most languages' type systems. This behavior is well covered by the graphql.org best-practices section. |
Thanks for the pointer. And "use non-null to explicitly opt in to error propagation" is very elucidating. I wish the spec would also make this more clear. |
https://spec.graphql.org/draft/#sec-Errors-and-Non-Nullability describes that any error in a non-null field should be propagated to its parent field, destroying the parent. This applies recursively to further ancestor fields, and across arrays with non-null members (if one member is null, the whole array should be destroyed).
Thus all ancestors are destroyed for a failure of any one of their descendants, if there is a chain of non-null fields going up from such descendants.
This destructive behavior is reminiscent of first-order logic, where one contradiction (being able to infer false) renders the whole system useless (you can infer anything).
Such behavior is brittle and I consider it harmful for real-world data integration scenarios, which I think is a major use case for GraphQL. When building a Knowledge Graph, you may have a field that's non-null and is valid in 99.99% of cases, but due to data quality problems there's almost always a tiny percentage of missing or malformed values that will cause such destruction.
This destructive behavior is implemented in some key software, and that harms our development efforts in the Ontotext Platform (which implements GraphQL over RDF Knowledge Graphs), see https://www.apollographql.com/docs/react/data/error-handling/
https://www.apollographql.com/blog/using-nullability-in-graphql-2254f84c4ed7 by @stubailo explains related issues in detail. In particular "For output fields, removing non-null from a field is a breaking change".
All this means that you can never use non-null, except for fields such as ID without which you can't even find the object. Which weakens the GraphQL schema, eg leaves fewer clues for data entry UIs.
(Note: #259 is a bit related)
The text was updated successfully, but these errors were encountered: