@@ -4,6 +4,7 @@ import com.expedia.graphql.TopLevelObject
4
4
import com.expedia.graphql.exceptions.InvalidInputFieldTypeException
5
5
import com.expedia.graphql.testSchemaConfig
6
6
import com.expedia.graphql.toSchema
7
+ import graphql.schema.GraphQLInterfaceType
7
8
import graphql.schema.GraphQLObjectType
8
9
import graphql.schema.GraphQLUnionType
9
10
import org.junit.jupiter.api.Assertions.assertThrows
@@ -35,7 +36,7 @@ internal class PolymorphicTests {
35
36
fun `SchemaGenerator can expose an interface and its implementations` () {
36
37
val schema = toSchema(queries = listOf (TopLevelObject (QueryWithInterface ())), config = testSchemaConfig)
37
38
38
- val interfaceType = schema.getType(" AnInterface" )
39
+ val interfaceType = schema.getType(" AnInterface" ) as ? GraphQLInterfaceType
39
40
assertNotNull(interfaceType)
40
41
41
42
val implementationType = schema.getObjectType(" AnImplementation" )
@@ -60,7 +61,7 @@ internal class PolymorphicTests {
60
61
61
62
@Test
62
63
fun `Object types implementing union and interfaces are only created once` () {
63
- val schema = toSchema(queries = listOf (TopLevelObject (QueryWithInterfaceAnUnion ())), config = testSchemaConfig)
64
+ val schema = toSchema(queries = listOf (TopLevelObject (QueryWithInterfaceAndUnion ())), config = testSchemaConfig)
64
65
65
66
val carType = schema.getType(" Car" ) as ? GraphQLObjectType
66
67
assertNotNull(carType)
@@ -79,6 +80,19 @@ internal class PolymorphicTests {
79
80
val personType = schema.getType(" Person" )
80
81
assertNotNull(personType)
81
82
}
83
+
84
+ @Test
85
+ fun `Abstract classes should be converted to interfaces` () {
86
+ val schema = toSchema(queries = listOf (TopLevelObject (QueryWithAbstract ())), config = testSchemaConfig)
87
+
88
+ val abstractInterface = schema.getType(" MyAbstract" ) as ? GraphQLInterfaceType
89
+ assertNotNull(abstractInterface)
90
+
91
+ val classWithBaseAbstractType = schema.getObjectType(" MyClass" )
92
+ assertNotNull(classWithBaseAbstractType)
93
+ assertEquals(1 , classWithBaseAbstractType.interfaces.size)
94
+ assertEquals(classWithBaseAbstractType.interfaces.first(), abstractInterface)
95
+ }
82
96
}
83
97
84
98
class QueryWithInterface {
@@ -128,7 +142,7 @@ data class Arm(
128
142
val value : Boolean
129
143
) : BodyPart
130
144
131
- class QueryWithInterfaceAnUnion {
145
+ class QueryWithInterfaceAndUnion {
132
146
fun product (): Product = Car (" DB9" , " black" )
133
147
}
134
148
@@ -156,3 +170,16 @@ data class Father(
156
170
val dadJoke : String ,
157
171
override val child : Person ?
158
172
) : Person
173
+
174
+ class QueryWithAbstract {
175
+ fun query (): MyAbstract = MyClass (id = 1 , name = " JUnit" )
176
+
177
+ fun queryImplementation (): MyClass = MyClass (id = 1 , name = " JUnit_2" )
178
+ }
179
+
180
+ @Suppress(" UnnecessaryAbstractClass" )
181
+ abstract class MyAbstract {
182
+ abstract val id: Int
183
+ }
184
+
185
+ data class MyClass (override val id : Int , val name : String ) : MyAbstract()
0 commit comments