Skip to content

Best practices for handling optional arguments? #388

Closed
@alexgenco

Description

@alexgenco

We just updated graphql-java-tools from 5.4.1 and the biggest change is around nullable input fields (I think caused by #315).

Previously, we were defining our resolver methods with Optional<> arguments for those that are nullable in the schema, e.g. first in

customers(input: CustomerSearchInput!, first: Int): [Customer!]

... mapped to the following resolver method:

public List<Customer> getCustomers(CustomerSearchInput input, Optional<Integer> first) { ... }

Previously, the first argument was Optional.empty() regardless of whether the client passed an explicit first: null or didn't pass the argument at all. However, now we are getting null when the client doesn't pass the argument, which requires us to handle both null and Optional.empty in all resolver methods with optional arguments.

Is there a way to opt-out of this new behavior? Or if not, a recommended way to unify handling of null and absence? e.g. in the object mapper configurer or something?

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