Skip to content

Absence of Optional arguments are represented with Optional.empty() instead of null #1586

Closed

Description

@asfernandes

Accordingly to graphql/graphql-spec#83 there is a distinction of null and absence of value in fields and arguments.

In graphql-java (using with the spring boot package) an Optional field respects that, i.e., absence sets the field to Java null and GraphQL null sets the field to Optional.empty().

However, in method arguments absence of value sets the Optional argument to Optional.empty(), not allowing to distinguish it from explicit GraphQL null.

Activity

  1. bbakerman commented on Jul 13, 2019

    @bbakerman
    Member

    Can you outline in more details what you would expect to happen for Optional argument values.

    The graphql-java "argument and validation" code we written on Java 6 originally (hence no optional).
    Hence it does use Optional well. The "field value" optional work was added much later.

    The other question I have is around how you see "http requests of say json" being able to produce optional arguments versus null ones. json conversion is not a direct graphql-java concern - however if we end up with Optional argument code that no framework can produce inputs for then it wont be useful.

  2. asfernandes commented on Jul 14, 2019

    @asfernandes
    Author
  3. bbakerman commented on Jul 15, 2019

    @bbakerman
    Member

    Are you using a library built on top of graphql-java. We do no mapping of java classes to to input types is why I ask?

    I know we don;t have code to handle Optional inside out argument parsing code (I am not arguing that) but I want to get a better understanding of your runtime.

    For example are you using the kickstart spring starters or some other Java -> graphql library framework?

  4. asfernandes commented on Jul 15, 2019

    @asfernandes
    Author

    Yes, I'm using the spring boot starter (which also uses graphql-java-tools).

  5. andimarek commented on Jul 18, 2019

    @andimarek
    Member

    @asfernandes I think this is the wrong project: we are not setting any fields to null/optional.
    Please report it to the spring booter/graphql java tools project.

    Thanks.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions