Skip to content

Support for Optional argument handling #966

Closed
@PhilippS93

Description

@PhilippS93

First of all, thank you for the library, it's very great! 👏

Is your feature request related to a problem? Please describe.
GraphQL supports 3 states of input arguments.

  • They can be set but null
  • They can be not set
  • They can be set and not null

Java only represents two states, set or not set. But the information if the property was present in the request is missing.
GraphQL Frameworks for java like graphql-java-kickstart/graphql-java-tools#404 support this feature by using Optional<>-java class.

Describe the solution you'd like
Add a toggle in the generation to generate Optional<> fields in input-classes.

e.g. for

input EditUserInput {
    id: ID!
    name: String!
    address: String
}

it currently generates:

public class EditUserInputDTO implements java.io.Serializable {

    @javax.validation.constraints.NotNull
    private String id;
    @javax.validation.constraints.NotNull
    private String name;
    private String address;
  //...
}

but now, we could generate:

public class EditUserInput DTO implements java.io.Serializable {

    @javax.validation.constraints.NotNull
    private String id;
    @javax.validation.constraints.NotNull
    private String name;
    private Optional<String> address;
  //...
}

This would allow us to check if the property should be deleted (Optional.empty() == false but null) or was just not set by the frontend (Optional.empty() == true) and must not be considered for updating or deletion.

Describe alternatives you've considered
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions