Skip to content

Commit 2e21d2a

Browse files
committed
Add test coverage for all nullabilty strengthening cases
1 parent f6e7ca7 commit 2e21d2a

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import graphql.TestUtil
44
import graphql.schema.GraphQLInterfaceType
55
import graphql.schema.GraphQLObjectType
66
import spock.lang.Specification
7+
import spock.lang.Unroll
78

89
import static SchemaValidationErrorType.ObjectDoesNotImplementItsInterfaces
910
import static graphql.Scalars.GraphQLBoolean
@@ -312,28 +313,51 @@ class TypesImplementInterfacesTest extends Specification {
312313
!badErrorCollector.getErrors().isEmpty()
313314
}
314315

315-
def "non-null union field implements nullable union interface field"() {
316+
@Unroll
317+
def "implementing field can strengthen #kind nullability from #interfaceFieldType to #implementingFieldType"() {
316318
when:
317-
TestUtil.schema('''
319+
TestUtil.schema("""
318320
schema { query: B }
319321
320-
union U = A
322+
enum E {
323+
VALUE
324+
}
321325
322-
interface I {
323-
i: U
326+
interface J {
327+
value: String
324328
}
325329
326-
type A {
327-
a: String
330+
type A implements J {
331+
value: String
332+
}
333+
334+
union U = A
335+
336+
interface I {
337+
value: $interfaceFieldType
328338
}
329339
330340
type B implements I {
331-
i: U!
341+
value: $implementingFieldType
332342
}
333-
''')
343+
""")
334344

335345
then:
336346
noExceptionThrown()
347+
348+
where:
349+
kind | interfaceFieldType | implementingFieldType
350+
"scalar" | "String" | "String!"
351+
"enum" | "E" | "E!"
352+
"object" | "A" | "A!"
353+
"interface" | "J" | "J!"
354+
"union" | "U" | "U!"
355+
"list" | "[String]" | "[String]!"
356+
"list item" | "[String]" | "[String!]"
357+
"list and item" | "[String]" | "[String!]!"
358+
"nested list" | "[[String]]" | "[[String!]!]!"
359+
"list of unions" | "[U]" | "[U!]!"
360+
"list of interfaces" | "[J]" | "[J!]!"
337361
}
338362

339363
def "field is a non null object"() {

0 commit comments

Comments
 (0)