Skip to content

allow Coercing.parseLiteral to return null (remove @NonNull annotation) #2904

Closed

Description

@sgerke-1L

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

Activity

  1. bbakerman commented on Aug 3, 2022

    @bbakerman
    Member

    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 CoercingParseLiteralException if 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

  2. sgerke-1L commented on Aug 5, 2022

    @sgerke-1L
    Author

    I found this previous discussion: #1362
    Somehow the @NonNull was removed from serialize but not from parseLiteral.

  3. added this to the 20.0 milestone on Aug 24, 2022
  4. bbakerman commented on Aug 24, 2022

    @bbakerman
    Member

    This has been fixed

  5. sgerke-1L commented on Aug 25, 2022

    @sgerke-1L
    Author

    Thanks for addressing this with #2912

  6. andimarek commented on Aug 26, 2022

    @andimarek
    Member

    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).

  7. andimarek commented on Aug 26, 2022

    @andimarek
    Member

    @sgerke-1L can you explain why you would want to return null for not null literal value? thanks

  8. sgerke-1L commented on Aug 26, 2022

    @sgerke-1L
    Author

    Motivation was the handling of NullValue in ObjectScalar. The null return was causing problems with spotbugs validation.

  9. sgerke-1L commented on Aug 26, 2022

    @sgerke-1L
    Author

    Is it easy to see that NullValue is never passed?

  10. andimarek commented on Aug 26, 2022

    @andimarek
    Member

    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.

  11. dondonz commented on Aug 30, 2022

    @dondonz
    Member

    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.

  12. sgerke-1L commented on Sep 7, 2022

    @sgerke-1L
    Author

    Thanks, this solves our problem: The inconsistency now resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions