diff --git a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt index ee1d217a..788d09ee 100644 --- a/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt +++ b/src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt @@ -400,7 +400,7 @@ class SchemaParser internal constructor( throw SchemaError("Expected type '${typeDefinition.name}' to be a ${expectedType.simpleName}, but it wasn't! " + "Was a type only permitted for object types incorrectly used as an input type, or vice-versa?") } - GraphQLTypeReference(typeDefinition.name) + inputObjects.find { it.name == typeDefinition.name } ?: GraphQLTypeReference(typeDefinition.name) } } else -> throw SchemaError("Unknown type: $typeDefinition") diff --git a/src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt b/src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt index 3b6c3783..263745be 100644 --- a/src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt +++ b/src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt @@ -3,6 +3,11 @@ package graphql.kickstart.tools import graphql.kickstart.tools.resolver.FieldResolverError import graphql.schema.GraphQLInterfaceType import graphql.schema.GraphQLObjectType +import graphql.schema.GraphQLArgument +import graphql.schema.GraphQLInputObjectType +import graphql.schema.GraphQLNonNull +import graphql.schema.idl.SchemaDirectiveWiring +import graphql.schema.idl.SchemaDirectiveWiringEnvironment import org.junit.Before import org.junit.Rule import org.junit.Test @@ -479,6 +484,47 @@ class SchemaParserTest { class Poodle(override var traits: List) : Dog() } + @Test + fun `NonNull and nullable input arguments should resolve to GraphQLInputObjectType`() { + val schema = SchemaParser.newParser() + .schemaString( + """ + type Query { + testNonNullable(filter: Filter!): Boolean + testNullable(filter: Filter): Boolean + } + + input Filter { + filter: String + } + """) + .resolvers(object : GraphQLQueryResolver { + fun testNonNullable(filter: Filter): Boolean = false + fun testNullable(filter: Filter): Boolean = false + }) + .directiveWiring(object : SchemaDirectiveWiring { + override fun onArgument(environment: SchemaDirectiveWiringEnvironment): GraphQLArgument { + when (environment.element.type) { + is GraphQLNonNull -> + assert((environment.element.type as GraphQLNonNull).wrappedType is GraphQLInputObjectType) + } + return environment.element + } + }) + .build() + .makeExecutableSchema() + + val testNonNullableArgument = schema.getObjectType("Query") + .getFieldDefinition("testNonNullable") + .arguments.first() + val testNullableArgument = schema.getObjectType("Query") + .getFieldDefinition("testNullable") + .arguments.first() + assert(testNonNullableArgument.type is GraphQLNonNull) + assert((testNonNullableArgument.type as GraphQLNonNull).wrappedType is GraphQLInputObjectType) + assert(testNullableArgument.type is GraphQLInputObjectType) + } + enum class EnumType { TEST }