Skip to content

Support for Optional when returning nullable types #269

@paul-pop

Description

@paul-pop

Thank you for the library, it's great! 👏

Is your feature request related to a problem? Please describe.
Because the query resolvers return the nullable object (without wrapping it in Optional) it can feel outdated for people heavily using Java8+ features.

Describe the solution you'd like
Currently when you have a query that has a nullable return type like this:

type Query {
    user(id: ID!): User
}

the generated code is:

@Override
public User user(final String id) {
    return null;
}

Would be nice to have a flag to enable/disable behaviour that allows the generation for nullable return types to use Optional instead which can make it easier to write neater code in the resolver.

@Override
public Optional<User> user(final String id) {
    return Optional.empty();
}

Describe alternatives you've considered
None

Additional context
None

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions