Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 4 additions & 11 deletions src/main/java/graphql/schema/validation/NoUnbrokenInputCycles.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import graphql.schema.GraphQLInputObjectField;
import graphql.schema.GraphQLInputObjectType;
import graphql.schema.GraphQLInputType;
import graphql.schema.GraphQLList;
import graphql.schema.GraphQLNonNull;
import graphql.schema.GraphQLSchemaElement;
import graphql.schema.GraphQLType;
Expand Down Expand Up @@ -63,17 +62,11 @@ private void check(GraphQLInputObjectType type, Set<GraphQLType> seen, List<Stri
}

private GraphQLType unwrapNonNull(GraphQLNonNull type) {
if (isList(type.getWrappedType())) {
//we only care about [type!]! i.e. non-null lists of non-nulls
GraphQLList listType = (GraphQLList) type.getWrappedType();
if (isNonNull(listType.getWrappedType())) {
return unwrapAll(listType.getWrappedType());
} else {
return type.getWrappedType();
}
} else {
return unwrapAll(type.getWrappedType());
GraphQLType wrappedType = type.getWrappedType();
if (isList(wrappedType)) {
return wrappedType;
}
return unwrapAll(wrappedType);
}

private String getErrorMessage(List<String> path) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package graphql.schema.validation

import graphql.TestUtil
import graphql.schema.GraphQLArgument
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLInputObjectField
import graphql.schema.GraphQLInputObjectType
import graphql.schema.idl.SchemaGenerator
import graphql.schema.idl.SchemaParser
import graphql.util.TraverserContext
import spock.lang.Specification

Expand Down Expand Up @@ -43,4 +46,51 @@ class NoUnbrokenInputCyclesTest extends Specification {
then:
errorCollector.containsValidationError(SchemaValidationErrorType.UnbrokenInputCycle)
}

def "input object cycles through a non-null list are allowed"() {
def sdl = """
input Example {
self: [Example!]!
value: String
}

type Query {
example(example: Example): String
}
"""

when:
def registry = new SchemaParser().parse(sdl)
new SchemaGenerator().makeExecutableSchema(registry, TestUtil.getMockRuntimeWiring())

then:
noExceptionThrown()
}

def "longer input object cycles through a non-null list are allowed"() {
def sdl = """
input Foo {
bar: Bar!
}

input Bar {
baz: Baz!
}

input Baz {
foos: [Foo!]!
}

type Query {
foo(foo: Foo): String
}
"""

when:
def registry = new SchemaParser().parse(sdl)
new SchemaGenerator().makeExecutableSchema(registry, TestUtil.getMockRuntimeWiring())

then:
noExceptionThrown()
}
}