FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix input cycle validation for non-null lists by andimarek · Pull Request #4386 · graphql-java/graphql-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .groovy  (1) .java  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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()
}
}

Back | FazBrowse Home | New Git URL