allow Coercing.parseLiteral to return null (remove @NonNull annotation)
Coercing.parseLiteral is declared to return a @NonNull value.
However, a coercing may want to return null for the NullValue. See for example the ObjectScalar implementation in https://github.com/graphql-java/graphql-java-extended-scalars
Hmm this is an intersting one - on the one hand the code is like that to say
- always return a value
- Most of the time there should be a value
- throw
CoercingParseLiteralExceptionif there is a problem in the conversion
I guess that the AST NullValue is mostly like going to result in a scalr saying its raw value for that is null
I found this previous discussion: https://github.com/graphql-java/graphql-java/issues/1362
Somehow the @NonNull was removed from serialize but not from parseLiteral.
This has been fixed
Thanks for addressing this with #2912
sorry to open it again, but the implementation of ObjectScalar is actually wrong: we never pass in NullValue (it is automatically converted to Java null).
@sgerke-1L can you explain why you would want to return null for not null literal value? thanks
Motivation was the handling of NullValue in ObjectScalar. The null return was causing problems with spotbugs validation.
Is it easy to see that NullValue is never passed?
Not sure what you mean with easy: if you look into the GraphQL Java source code you can find it.
It should be clearly documented I would say.
On the follow up discussion - the NullValue case in ObjectScalar's parseLiteral implementation has been removed, as a NullValue literal input will coerced as null & returned before the scalar's parseLiteral method is called. Added more documentation to make this clearer inside Coercing.
Thanks, this solves our problem: The inconsistency now resolved.