Replies: 3 comments 13 replies
-
I voted "no" cause null propagation feels a bit awkward. Using null for both actual values and errors feels dangerous. I'm curious if there has ever been talks about using "undefined" for errors instead? {
"data": {
"hero": {
"name": "Luke"
// no height here because the height field threw an error
}
},
"errors": [
{
"message": "Cannot fetch height",
"path": ["hero", "height"]
}
]
} Then there's no risk of cache poisoning. |
Beta Was this translation helpful? Give feedback.
-
As we've learned from CCN discussions, null propagation has far reaching effects. The official recommendation is to rarely make fields Non-Nullable, basically dissuading users from using a feature of the language. Relay has a very long history of dealing with null propagation by basically operating outside of the GraphQL spec with a facade of fragment isolation along with several other adaptations to avoid blowing out their normalized cache. They, along with the Kotlin Apollo client, and Netflix each independently introduced directives that act something like CCN, and now they're working on Here is a recent writeup about how CCN can be used to prevent the destructive impact of null propagation on Relay's caches: graphql/nullability-wg#20 CCN has been in the works for well over 2 years now, a lot of that time spent trying to work through all of the subtle ways null propagation can cause issues for clients. It's not clear to me for what use case null propagation is desirable behavior. If it wouldn't be so horrendously breaking, I'd suggest that null propagation be re-evaluated and removed in the next major version of GraphQL. An opt-in experimental feature might be more viable. Possible non-destructive replacement behavior:
|
Beta Was this translation helpful? Give feedback.
-
I think if we were to write a new GraphQL 2.0, I would:
I think it's critical that GraphQL responses match the types given in the schema, and without indicating these again through the response a schema-unaware client wouldn't know whether to bubble the null or not. Similarly simply omitting errored fields would break the expectation of developers for schema-unaware clients - they've asked for One of the most common issues I see with people using GraphQL is people not using fragments. This is something we should all work on improving - encouraging the best practices of using fragments widely and co-locating data requirements with components. I read @jensneuse's post https://wundergraph.com/blog/graphql_doesnt_solve_underfetching_overfetching_but_relay recently and the examples of just how many GraphQL queries these sites are issuing really indicates that we're not educating people enough of how they should use GraphQL. But I'm getting a little off topic, so I'll shut up about that... |
Beta Was this translation helpful? Give feedback.
-
I want to say up front that CCN should absolutely not be blocked on this discussion.
During our work on CCN, we've run into quite a few holes in GQL, error handling, fragment modularity, feature introspection, etc, but I'm not sure we've ever asked the most base question: Is null propagation still desirable in 2023?
From the spec:
I basically would like to float the possibility that rather than creating the a feature (CCN) to adapt to null propagation, null propagation itself could be removed or altered so it isn't so problematic.
Please discuss the reason for your answer in the comments.
5 votes ·
Beta Was this translation helpful? Give feedback.
All reactions