Skip to content

Commit 580475b

Browse files
authored
Merge pull request #435 from elielsonms/#434_GraphQlInputObjectType_at_runtime_wiring_on_nonnull_input
#434 Add GraphQlInputObjectType reference for NonNull INput types at …
2 parents 7c0e22f + 4c26e36 commit 580475b

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/main/kotlin/graphql/kickstart/tools/SchemaParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class SchemaParser internal constructor(
400400
throw SchemaError("Expected type '${typeDefinition.name}' to be a ${expectedType.simpleName}, but it wasn't! " +
401401
"Was a type only permitted for object types incorrectly used as an input type, or vice-versa?")
402402
}
403-
GraphQLTypeReference(typeDefinition.name)
403+
inputObjects.find { it.name == typeDefinition.name } ?: GraphQLTypeReference(typeDefinition.name)
404404
}
405405
}
406406
else -> throw SchemaError("Unknown type: $typeDefinition")

src/test/kotlin/graphql/kickstart/tools/SchemaParserTest.kt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ package graphql.kickstart.tools
33
import graphql.kickstart.tools.resolver.FieldResolverError
44
import graphql.schema.GraphQLInterfaceType
55
import graphql.schema.GraphQLObjectType
6+
import graphql.schema.GraphQLArgument
7+
import graphql.schema.GraphQLInputObjectType
8+
import graphql.schema.GraphQLNonNull
9+
import graphql.schema.idl.SchemaDirectiveWiring
10+
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
611
import org.junit.Before
712
import org.junit.Rule
813
import org.junit.Test
@@ -479,6 +484,47 @@ class SchemaParserTest {
479484
class Poodle(override var traits: List<PoodleTrait>) : Dog<PoodleTrait>()
480485
}
481486

487+
@Test
488+
fun `NonNull and nullable input arguments should resolve to GraphQLInputObjectType`() {
489+
val schema = SchemaParser.newParser()
490+
.schemaString(
491+
"""
492+
type Query {
493+
testNonNullable(filter: Filter!): Boolean
494+
testNullable(filter: Filter): Boolean
495+
}
496+
497+
input Filter {
498+
filter: String
499+
}
500+
""")
501+
.resolvers(object : GraphQLQueryResolver {
502+
fun testNonNullable(filter: Filter): Boolean = false
503+
fun testNullable(filter: Filter): Boolean = false
504+
})
505+
.directiveWiring(object : SchemaDirectiveWiring {
506+
override fun onArgument(environment: SchemaDirectiveWiringEnvironment<GraphQLArgument>): GraphQLArgument {
507+
when (environment.element.type) {
508+
is GraphQLNonNull ->
509+
assert((environment.element.type as GraphQLNonNull).wrappedType is GraphQLInputObjectType)
510+
}
511+
return environment.element
512+
}
513+
})
514+
.build()
515+
.makeExecutableSchema()
516+
517+
val testNonNullableArgument = schema.getObjectType("Query")
518+
.getFieldDefinition("testNonNullable")
519+
.arguments.first()
520+
val testNullableArgument = schema.getObjectType("Query")
521+
.getFieldDefinition("testNullable")
522+
.arguments.first()
523+
assert(testNonNullableArgument.type is GraphQLNonNull)
524+
assert((testNonNullableArgument.type as GraphQLNonNull).wrappedType is GraphQLInputObjectType)
525+
assert(testNullableArgument.type is GraphQLInputObjectType)
526+
}
527+
482528
enum class EnumType {
483529
TEST
484530
}

0 commit comments

Comments
 (0)