Skip to content

Declaring an argument with java.util.Optional results in input being double wrapped with Optional #156

Closed
@janujc

Description

@janujc

Hi, I'm on 1.0.0-M2 and trying to create a handler for a method with an optional field.

@QueryMapping
public Example example(@Argument Optional<String> relatedString) {
    return exampleService.getExample(relatedString);
}

However, I keep getting the following response:

{
    "errors": [
        {
            "message": "class java.util.Optional cannot be cast to class java.lang.String (java.util.Optional and java.lang.String are in module java.base of loader 'bootstrap')",
            "locations": [
                {
                    "line": 2,
                    "column": 5
                }
            ],
            "path": [
                "example"
            ],
            "extensions": {
                "classification": "INTERNAL_ERROR"
            }
        }
    ],
    "data": {
        "example": null
    }
}

When debugging, I found that relatedString was being double wrapped with Optional at runtime. In other words, the input to the method is actually Optional[Optional[stringThatMayBeHere]]. I assume that this is not intentional.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions