Skip to content

Commit 304954c

Browse files
smyrickShane Myrick
andauthored
Add test to verify interface implementations can be ignored (#846)
Co-authored-by: Shane Myrick <accounts@shanemyrick.com>
1 parent 2b1cc1a commit 304954c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/test/integration/InterfaceOfInterfaceTest.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
package com.expediagroup.graphql.test.integration
1818

1919
import com.expediagroup.graphql.TopLevelObject
20+
import com.expediagroup.graphql.annotations.GraphQLIgnore
21+
import com.expediagroup.graphql.extensions.deepName
2022
import com.expediagroup.graphql.testSchemaConfig
2123
import com.expediagroup.graphql.toSchema
2224
import graphql.schema.GraphQLInterfaceType
2325
import org.junit.jupiter.api.Test
2426
import kotlin.test.assertEquals
2527
import kotlin.test.assertNotNull
28+
import kotlin.test.assertNull
2629

2730
class InterfaceOfInterfaceTest {
2831

2932
@Test
3033
fun `interface of interface`() {
3134
val queries = listOf(TopLevelObject(InterfaceOfInterfaceQuery()))
3235
val schema = toSchema(queries = queries, config = testSchemaConfig)
33-
assertEquals(expected = 1, actual = schema.queryType.fieldDefinitions.size)
36+
assertEquals(expected = 2, actual = schema.queryType.fieldDefinitions.size)
3437

3538
val implementation = schema.getObjectType("MyClass")
3639
assertNotNull(implementation)
@@ -49,6 +52,19 @@ class InterfaceOfInterfaceTest {
4952
assertNotNull(firstLevelInterface)
5053
}
5154

55+
@Test
56+
fun `ignore class and use interface as type`() {
57+
val queries = listOf(TopLevelObject(InterfaceOfInterfaceQuery()))
58+
val schema = toSchema(queries = queries, config = testSchemaConfig)
59+
60+
// The ignored class should not be in the schema at all
61+
assertNull(schema.getType("IgnoredClass"))
62+
63+
assertEquals(expected = 2, actual = schema.queryType.fieldDefinitions.size)
64+
val queryField = assertNotNull(schema.queryType.getFieldDefinition("getIgnoredClass"))
65+
assertEquals("SecondLevel!", queryField.type.deepName)
66+
}
67+
5268
interface FirstLevel {
5369
val id: String
5470
}
@@ -61,5 +77,12 @@ class InterfaceOfInterfaceTest {
6177

6278
class InterfaceOfInterfaceQuery {
6379
fun getClass() = MyClass(id = "1", name = "fooBar")
80+
fun getIgnoredClass(): SecondLevel = IgnoredClass(id = "2", name = "baz")
6481
}
82+
83+
@GraphQLIgnore
84+
class IgnoredClass(
85+
override val id: String,
86+
override val name: String
87+
) : SecondLevel
6588
}

0 commit comments

Comments
 (0)