Skip to content

OneOf not validated inside a list #3366

@rideliner

Description

@rideliner

When the type of an argument is a list of @oneOf input objects, those values are not validated.

Test for src/test/groovy/graphql/execution/ValuesResolverTest.groovy

   def "getArgumentValues: invalid oneOf input validation applied with list of input type"() {
        given: "schema defining input object"
        def inputObjectType = newInputObject()
                .name("oneOfInputObject")
                .withAppliedDirective(Directives.OneOfDirective.toAppliedDirective())
                .field(newInputObjectField()
                        .name("a")
                        .type(GraphQLString)
                        .build())
                .field(newInputObjectField()
                        .name("b")
                        .type(GraphQLInt)
                        .build())
                .build()

        def inputValue = buildObjectLiteral([
                oneOfField: [
                        a: StringValue.of("abc"),
                        b: IntValue.of(123)
                ]
        ])
        def inputArray = ArrayValue.newArrayValue().value(inputValue).build()

        def argument = new Argument("arg", inputArray)

        when:
        def fieldArgumentList = newArgument().name("arg").type(list(inputObjectType)).build()
        ValuesResolver.getArgumentValues([fieldArgumentList], [argument], CoercedVariables.emptyVariables(), graphQLContext, locale)

        then:
        def e = thrown(OneOfTooManyKeysException)
        e.message == "Exactly one key must be specified for OneOf type 'oneOfInputObject'."
    }

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