You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Errors in a non-nullable field throw exception out of GraphQL.execute() #268
When an exception (field error) happens during resolution of a field, completeValue is called with a null resolvedValue. If the field is a GraphQLNonNull, that leads to a GraphQLException being thrown which is never caught.
According to the GraphQL spec, 6.4.4 Errors and Nullability (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), the null value should be propagated up to the parent field in this case (and if that is non-nullable, up again until ultimately a null value under the data key of the response object), without adding additional errors to the result error list.
Thanks for pointing this out. You are right. I will include a fix for this
for 2.3.0 unless you want to PR?
чт, 15 дек. 2016 г. в 11:37, Dirk <notifications@github.com>:
When an exception (field error) happens during resolution of a field,
completeValue is called with a null resolvedValue. If the field is a
GraphQLNonNull, that leads to a GraphQLException being thrown which is
never caught.
According to the GraphQL spec, 6.4.4 Errors and Nullability (
http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability), the
null value should be propagated up to the parent field in this case (and if
that is non-nullable, up again until ultimately a null value under the data
key of the response object), without adding additional errors to the result
error list.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#268>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AANWZTCfVFqY8KgcEPeMpiy6ar28xBD7ks5rIWzTgaJpZM4LOTPc>
.
Since Non-Null type fields cannot be null, field errors are propagated to be handled by the parent field. If the parent field may be null then it resolves to null, otherwise if it is a Non-Null type, the field error is further propagated to it’s parent field.
If all fields from the root of the request to the source of the error return Non-Null types, then the "data" entry in the response should be null.
Currently the invocation of resolveField is recursive. It descends down into the child fields but it does NOT allow for a result such that this non null precondition can bubble up to the calling layers.
Today is considers the parent object "resolved" then looks for child field objects. But if one of the children is non null then it must make the parent null and the code today cant easily do that. I think this will take some refactoring to come to spec
Also another hard problem here is the AbstractExecutionStrategy uses inheritance and hence each other type level code MUST now handle this exception themselves, and it cant be done in once place
OK having struggled with a fix for this locally I think the fundamental problem is that the graphql types system we have in the library does not hold hierarchy information and the concept of non nullness on the type itself
Activity
dminkovsky commentedon Dec 15, 2016
dllx commentedon Dec 16, 2016
Thank you, that would be great. No, I don't have a patch for that ready, sorry.
dminkovsky commentedon Jan 3, 2017
This didn't make 2.3.0 but should be included in 2.4.0. Thanks again for reporting @dllx.
jplock commentedon Jan 3, 2017
@dminkovsky when 2.4.0 is tagged, would it be possible to update https://github.com/graphql-java/graphql-java-servlet as well?
dminkovsky commentedon Jan 3, 2017
I believe graphql-java-servlet is maintained by @yrashk. Any particular reason not 2.3.0, too?
jplock commentedon Jan 3, 2017
Nope, it wasn't updated for 2.3.0 yet either, but that would be appreciated. :)
vojtechmasa commentedon Mar 5, 2017
Do you have ETA to resolve this issue? Thank you.
bbakerman commentedon Apr 1, 2017
I started to look into this problem and the code as is has some serious trouble in implementing this
The spec says
http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability
Currently the invocation of resolveField is recursive. It descends down into the child fields but it does NOT allow for a result such that this non null precondition can bubble up to the calling layers.
Today is considers the parent object "resolved" then looks for child field objects. But if one of the children is non null then it must make the parent null and the code today cant easily do that. I think this will take some refactoring to come to spec
this test should pass
bbakerman commentedon Apr 1, 2017
Also another hard problem here is the AbstractExecutionStrategy uses inheritance and hence each other type level code MUST now handle this exception themselves, and it cant be done in once place
bbakerman commentedon Apr 3, 2017
OK having struggled with a fix for this locally I think the fundamental problem is that the graphql types system we have in the library does not hold hierarchy information and the concept of non nullness on the type itself
The spec says http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability it should bubble up to the parent type
But we cant currently do that since the code only knows about the "current type" and graphqlnonnull type is a dumb simple wrapper.
So given a type T (that we have unwrapped) we cant easily answer the questions
I think we need to introduce a TypeInfo kind of thing for "execution" so we can help answer these questions
dllx commentedon Apr 3, 2017
Unfortunately, I have very few time looking into this. In my Ceylon implementation of a GraphQL engine (https://github.com/dlkw/ceylon-graphql, see code at https://github.com/dlkw/ceylon-graphql/blob/master/source/de/dlkw/graphql/exp/Schema.ceylon#L664) I have split the completeValues function and used an input flag to signal "this happens in a non null field" and a special return value to signal the error the non-null case.
Maybe this is transferrable to this project and you can take some inspiration from there.
graphql-java#268 - now follows spec in regard to null error handling
bbakerman commentedon Apr 3, 2017
Yeah I used exceptions in the new code which is logically equivalent to Either types X | Y
Merge pull request #353 from bbakerman/268-nonnull-error-handling
andimarek commentedon May 14, 2017
this solved by #353
Merge remote-tracking branch 'upstream/master'