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
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -395,7 +395,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
44 changes: 44 additions & 0 deletions src/test/groovy/graphql/kickstart/tools/SchemaParserSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ package graphql.kickstart.tools

import graphql.kickstart.tools.resolver.FieldResolverError
import graphql.language.SourceLocation
import graphql.schema.GraphQLArgument
import graphql.schema.GraphQLInputObjectType
import graphql.schema.GraphQLNonNull
import graphql.schema.GraphQLSchema
import graphql.schema.idl.SchemaDirectiveWiring
import graphql.schema.idl.SchemaDirectiveWiringEnvironment
import org.springframework.aop.framework.ProxyFactory
import spock.lang.Specification

Expand Down Expand Up @@ -368,6 +373,45 @@ class SchemaParserSpec extends Specification {
noExceptionThrown()
}

def "NonNull and nullable input arguments should resolve to 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 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 == GraphQLNonNull
(testNonNullableArgument.type as GraphQLNonNull).wrappedType.class == GraphQLInputObjectType
testNullableArgument.type.class == GraphQLInputObjectType
}

def "allow circular relations in input objects"() {
when:
SchemaParser.newParser().schemaString('''\
Expand Down