Can I return a partial success if one element of an array is invalid? #5889
-
Say I have a query that returns an array of Currently if my resolver just returns the array of all known customers, including the dodgy one, then the entire operation will fail with something like: {
"data": {
"customers": null
},
"errors": [{
"message": "Cannot return null for non-nullable field Customer.email"
// More error stuff here
}]
} I get that the validation is supposed to be strict, but now on my UI it fails to load the entire list of customers just because one of them is invalid. It makes it too easy for a single record to poison the entire database. What I would like is a way to still return the error, but to also have the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Null propagation through non-null types is part of the GraphQL spec. Would you like to end up with Would you like the bad customer's entry in the list to end up |
Beta Was this translation helpful? Give feedback.
Null propagation through non-null types is part of the GraphQL spec.
Would you like to end up with
null
as the bad customer's email? In that case, declare theemail
field as nullable (egString
instead ofString!
).Would you like the bad customer's entry in the list to end up
null
(alongside other entries which are non-null objects)? In that case, declare thecustomers
field as[Customer]
(or perhaps[Customer]!
) rather than as[Customer!]
.