Skip to content

Commit f6e7ca7

Browse files
committed
Fix non-null union field implements nullable union interface field
1 parent acc4678 commit f6e7ca7

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎src/main/java/graphql/schema/validation/TypesImplementInterfaces.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private SchemaValidationError error(String msg) {
189189
boolean isCompatible(GraphQLOutputType constraintType, GraphQLOutputType objectType) {
190190
if (isSameType(constraintType, objectType)) {
191191
return true;
192-
} else if (constraintType instanceof GraphQLUnionType) {
192+
} else if (constraintType instanceof GraphQLUnionType && objectType instanceof GraphQLObjectType) {
193193
return objectIsMemberOfUnion((GraphQLUnionType) constraintType, objectType);
194194
} else if (constraintType instanceof GraphQLInterfaceType && objectType instanceof GraphQLObjectType) {
195195
return objectImplementsInterface((GraphQLInterfaceType) constraintType, (GraphQLObjectType) objectType);

‎src/test/groovy/graphql/schema/validation/TypesImplementInterfacesTest.groovy‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package graphql.schema.validation
22

3+
import graphql.TestUtil
34
import graphql.schema.GraphQLInterfaceType
45
import graphql.schema.GraphQLObjectType
56
import spock.lang.Specification
@@ -311,6 +312,29 @@ class TypesImplementInterfacesTest extends Specification {
311312
!badErrorCollector.getErrors().isEmpty()
312313
}
313314

315+
def "non-null union field implements nullable union interface field"() {
316+
when:
317+
TestUtil.schema('''
318+
schema { query: B }
319+
320+
union U = A
321+
322+
interface I {
323+
i: U
324+
}
325+
326+
type A {
327+
a: String
328+
}
329+
330+
type B implements I {
331+
i: U!
332+
}
333+
''')
334+
335+
then:
336+
noExceptionThrown()
337+
}
314338

315339
def "field is a non null object"() {
316340
given:

0 commit comments

Comments
 (0)