Skip to content

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

Closed

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

Activity

  1. added this to the 18.0 milestone on Oct 8, 2021
  2. dondonz commented on Oct 8, 2021

    @dondonz
    Member

    Thanks @haneev! The fix has been merged in.

    The error message will now appear as

    Variable 'input' has an invalid value: Invalid input for Enum 'PositionType'. No value found for name 'UNKNOWN_POSITION'
    
  3. haneev commented on Oct 15, 2021

    @haneev
    Author

    Thanks @dondonz! Looking good! I will close the issue as resolved :)

  4. juriad commented on Nov 3, 2021

    @juriad

    I just found this issue during our upgrade from 15.0 to 17.3. Some of our tests started failing during the deserialization of a bad UUID (0000-0000) for a custom non-null scalar variable.

    Thanks for the fix, it looks good. How likely is it that there is going to be release 17.4?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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