Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid fields in variable ignored when an enum is present. #8025

Closed
faddiv opened this issue Feb 15, 2025 · 0 comments · Fixed by #8026
Closed

Invalid fields in variable ignored when an enum is present. #8025

faddiv opened this issue Feb 15, 2025 · 0 comments · Fixed by #8026

Comments

@faddiv
Copy link
Contributor

faddiv commented Feb 15, 2025

Product

Hot Chocolate

Version

15.0.3

Link to minimal reproduction

https://github.com/faddiv/graphql-platform/tree/fix-ignored-field-when-enum-is-present

Steps to reproduce

Example model:

public class User(string name)
{
    public string Name { get; set; } = name;
    public string? Surname { get; set; }
    public GenderEnum? Gender { get; set; }
}

public enum GenderEnum { Male, Female }

public class UserMutation
{
    public string AddUser(User user)
    {
        return $"{user.Name} {user.Surname} ({user.Gender}) was added!";
    }
}

Inputs

Execute the following GraphQL mutation:

mutation($user: UserInput!) { addUser(user: $user) }

With the following variables:

{
  "name": "Oliver",
  "surname": "Smith",
  "gender": "MALE",
  "foo": "bar"
}

What is expected?

{
  "errors": [
    {
      "message": "The field `foo` does not exist on the type `UserInput`.",
      "path": [
        "user"
      ],
      "extensions": {
        "type": "UserInput"
      }
    }
  ]
}

What is actually happening?

{
  "data": {
    "addUser": "Oliver Smith (Male) was added!"
  }
}

Relevant log output

Additional context

In normal cases, if a variable contains an invalid field, the request returns an error stating that the field does not exist. However, if one of the variables is an enum value, then the invalid field is silently ignored instead of triggering an error.

The issue appears to be in the VariableCoercionHelper class, specifically in the Rewrite method. When it attempts to determine the field type and does not find it, the method removes the invalid field. As a result, the validation step does not detect the issue.

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

Successfully merging a pull request may close this issue.

1 participant