Skip to content

Variables are coerced twice during an execution when a field validation instrumentation is active #2458

Closed

Description

@jenssuhr

Describe the bug
It looks like variables are coerced twice during an execution using graphql-java 16.2, once in execute and once in validateFieldsAndArguments. This breaks e.g. enums with non-default names.

Variables are first coerced here, then added to the execution context.
In FieldValidationSupport, the QueryTraverser is initialized with those variables from the execution context and coerces them again here.

To Reproduce
If you have an enum value defined like this

GraphQLEnumType.newEnum()
    .name("MyEnum")
    .description("My enum with all lowercase names.")
    .values(
        MyEnum.values().map {
            GraphQLEnumValueDefinition.newEnumValueDefinition()
                .name(it.getLowerCaseName())
                .value(it)
                .build()
        }
    ).build()

the first coercion works correctly, but the second one fails.

Activity

  1. dondonz commented on Jul 19, 2021

    @dondonz
    Member

    Hi @jenssuhr,

    I'm trying to investigate the issue but I can't reproduce the error. Could you please help me by expanding on your example?

    Could you please paste here:

    1. an example query,
    2. the field validation instrumentation(s) used, and
    3. the name of the error when the second coercion failed
  2. jenssuhr commented on Jul 26, 2021

    @jenssuhr
    Author

    Hi, thanks for investigating! I'll try to add an example as soon as possible.

  3. jenssuhr commented on Jul 26, 2021

    @jenssuhr
    Author

    I just noticed that we're not using the field validation correctly. Instead of using SimpleFieldValidation and adding rules, we were using a separate FieldValidationInstrumentation for each rule and chaining them together using ChainedInstrumentation. Fixing that will probably also fix this issue.
    Thank you for your help!

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions