Skip to content

Commit 2e956f4

Browse files
Silva ElielsonSilva Elielson
authored andcommitted
#434 Add GraphQlInputObjectType reference for NonNull INput types at Runtime Wiring
- Added to the determineType the same approeach as determineInputType, but without the creation of non existing INput types (this could lead to infinity recursion) - Added Groovy Unit Test to ensure the problem is solved
1 parent 97c4600 commit 2e956f4

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ class SchemaParser internal constructor(
392392
throw SchemaError("Expected type '${typeDefinition.name}' to be a ${expectedType.simpleName}, but it wasn't! " +
393393
"Was a type only permitted for object types incorrectly used as an input type, or vice-versa?")
394394
}
395-
GraphQLTypeReference(typeDefinition.name)
395+
val found = inputObjects.filter { it.name == typeDefinition.name }
396+
if (found.size == 1) {
397+
found[0]
398+
} else {
399+
GraphQLTypeReference(typeDefinition.name)
400+
}
396401
}
397402
}
398403
else -> throw SchemaError("Unknown type: $typeDefinition")

src/test/groovy/graphql/kickstart/tools/SchemaParserSpec.groovy

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ package graphql.kickstart.tools
22

33
import graphql.kickstart.tools.resolver.FieldResolverError
44
import graphql.language.SourceLocation
5+
import graphql.schema.GraphQLArgument
6+
import graphql.schema.GraphQLInputObjectType
7+
import graphql.schema.GraphQLInputType
8+
import graphql.schema.GraphQLNonNull
59
import graphql.schema.GraphQLSchema
10+
import graphql.schema.idl.SchemaDirectiveWiring
11+
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
612
import org.springframework.aop.framework.ProxyFactory
713
import spock.lang.Specification
814

@@ -368,6 +374,45 @@ class SchemaParserSpec extends Specification {
368374
noExceptionThrown()
369375
}
370376

377+
def "NonNull and nullable arguments returning it's GraphQLInputObjectType "() {
378+
when:
379+
GraphQLSchema schema = SchemaParser.newParser().schemaString('''\
380+
type Query {
381+
testNonNullable(filter: Filter!): Boolean
382+
testNullable(filter: Filter): Boolean
383+
}
384+
385+
input Filter {
386+
filter: String
387+
}
388+
'''.stripIndent())
389+
.resolvers(new GraphQLQueryResolver() {
390+
boolean testNonNullable(Filter filter) { false }
391+
boolean testNullable(Filter filter) { false }
392+
})
393+
.directiveWiring(new SchemaDirectiveWiring(){
394+
GraphQLArgument onArgument(SchemaDirectiveWiringEnvironment<GraphQLArgument> environment) {
395+
switch (environment.getElement().type.class) {
396+
case GraphQLNonNull:
397+
assert (environment.getElement().type as graphql.schema.GraphQLNonNull).wrappedType.class == GraphQLInputObjectType
398+
}
399+
return environment.getElement()
400+
}})
401+
.build()
402+
.makeExecutableSchema()
403+
404+
then:
405+
GraphQLArgument testNonNullableArgument = schema.getObjectType("Query")
406+
.getFieldDefinition("testNonNullable")
407+
.arguments.first()
408+
GraphQLArgument testNullableArgument = schema.getObjectType("Query")
409+
.getFieldDefinition("testNullable")
410+
.arguments.first()
411+
testNonNullableArgument.type.class == graphql.schema.GraphQLNonNull
412+
(testNonNullableArgument.type as graphql.schema.GraphQLNonNull).wrappedType.class == GraphQLInputObjectType
413+
testNullableArgument.type.class == GraphQLInputObjectType
414+
}
415+
371416
enum EnumType {
372417
TEST
373418
}

0 commit comments

Comments
 (0)