Skip to content

#434 Add GraphQlInputObjectType reference for NonNull INput types at … #435

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

Merged
2 changes: 1 addition & 1 deletion src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
46 changes: 46 additions & 0 deletions src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -479,6 +484,47 @@ class SchemaParserTest {
class Poodle(override var traits: List<PoodleTrait>) : Dog<PoodleTrait>()
}

@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>): 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
}
Expand Down