Skip to content

When sending an invalid enum value the error is not as expected #2560

@haneev

Description

@haneev

Describe the bug
When an invalid enum-value is send-in the error results in a weird chain of invalid value. Like this:

{
  "errors" : [ {
    "message" : "invalid value : invalid value : invalid value : Invalid input for Enum 'PositionType'. No value found for name 'UNKNOWN_POSITION'",
    "extensions" : {
      "classification" : "ValidationError"
    }
  } ]
}

To Reproduce

With the following schema:

enum PositionType {
MANAGER
DEVELOPER
}
input PersonInput {
name: String
position: PositionType
}

type Mutation {
  updatePerson(input: PersonInput!): Boolean
}

and request

mutation Mutation($input: PersonInput!) {
    updatePerson(data: $input)
}

vars
{
 "input": {
"name": "Name",
"position": "UNKNOWN_POSITION"
}
}

This is caused by the change related to default-values and a change in the ValuesResolver.java
Each type in the tree will add a invalid value : to the error message. So if you have a depth of 3 it will be three invalid values.

Another issue is that you don't know which field is actually invalid. The previous version of the code had the name of the field in the error message, which was way more convenient.

Previous message was: Variable 'position' has an invalid value: ...

I also encounter this for other types as well, same for sending "maybe" to a Boolean type. So probably other types will have the same issue as well?

graphql-java version 17.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions