Skip to content

GraphQLTypeReference instead of proper GraphQlInputObjectType during runtime (Directive wiring) on NonNull Input types #434

Closed

Description

@elielsonms

My team is using the graphql-java-extended-validation library and we identified that the validations would not execute when we add the validation on a NonNull input type. Initially, we thought this would be a bug there, but now we identified that this is happening because this validation library executes over the directive wiring, and sadly at that level of execution GraphQLArguments that are NonNull hasn't the proper GraphQLInputObjectType definition for it, just has the GraphQLTypeRefernce for that type, which will later be replaced on GraphQLSchema building method. But we need the proper InputObject Definition at runtime, at Directive Wiring.
I created a test case to illustrate this issue and also pushing a PR with the solution we found to have this reference properly set at runtime without falling into infinity recursion.

Test Case to illustrate the issue:

def "NonNull and nullable arguments returning it's GraphQLInputObjectType "() {
        when:
        GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
                    type Query { 
                        testNonNullable(filter: Filter!): Boolean
                        testNullable(filter: Filter): Boolean
                    }
                    input Filter {
                        filter: String
                    }
                '''.stripIndent())
                .resolvers(new GraphQLQueryResolver() {
                    boolean testNonNullable(Filter filter) { false }
                    boolean testNullable(Filter filter) { false }
                })
                .directiveWiring(new SchemaDirectiveWiring(){
                        GraphQLArgument onArgument(SchemaDirectiveWiringEnvironment<GraphQLArgument> environment) {
                            switch (environment.getElement().type.class) {
                                case GraphQLNonNull:
                                    assert (environment.getElement().type as graphql.schema.GraphQLNonNull).wrappedType.class == GraphQLInputObjectType
                            }
                            return environment.getElement()
                        }})
                .build()
                .makeExecutableSchema()

        then:
        GraphQLArgument testNonNullableArgument = schema.getObjectType("Query")
                .getFieldDefinition("testNonNullable")
                .arguments.first()
        GraphQLArgument testNullableArgument = schema.getObjectType("Query")
                .getFieldDefinition("testNullable")
                .arguments.first()
        testNonNullableArgument.type.class == graphql.schema.GraphQLNonNull
        (testNonNullableArgument.type as graphql.schema.GraphQLNonNull).wrappedType.class == GraphQLInputObjectType
        testNullableArgument.type.class == GraphQLInputObjectType
    }

Activity

  1. changed the title [-]GraphQLTypeRefernce instead of proper GraphQlInputObjectType during runtime (Directive wiring) on NonNull Input types[/-] [+]GraphQLTypeReference instead of proper GraphQlInputObjectType during runtime (Directive wiring) on NonNull Input types[/+] on Sep 16, 2020
  2. added a commit that references this issue on Sep 16, 2020
  3. elielsonms commented on Sep 16, 2020

    @elielsonms
    Author

    My Project is using version 6.1.0, so would be great if this commit could be cherry-picked to a release 6.1.1 because would be very hard for us to migrate to the graphl-java 15. Case it's not possible we'll host a customized version from release 6.1.0 tag.

  4. added a commit that references this issue on Mar 5, 2021
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