@@ -4,6 +4,7 @@ import com.expedia.graphql.TopLevelObject
44import com.expedia.graphql.exceptions.InvalidInputFieldTypeException
55import com.expedia.graphql.testSchemaConfig
66import com.expedia.graphql.toSchema
7+ import graphql.schema.GraphQLInterfaceType
78import graphql.schema.GraphQLObjectType
89import graphql.schema.GraphQLUnionType
910import org.junit.jupiter.api.Assertions.assertThrows
@@ -35,7 +36,7 @@ internal class PolymorphicTests {
3536 fun `SchemaGenerator can expose an interface and its implementations` () {
3637 val schema = toSchema(queries = listOf (TopLevelObject (QueryWithInterface ())), config = testSchemaConfig)
3738
38- val interfaceType = schema.getType(" AnInterface" )
39+ val interfaceType = schema.getType(" AnInterface" ) as ? GraphQLInterfaceType
3940 assertNotNull(interfaceType)
4041
4142 val implementationType = schema.getObjectType(" AnImplementation" )
@@ -60,7 +61,7 @@ internal class PolymorphicTests {
6061
6162 @Test
6263 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)
6465
6566 val carType = schema.getType(" Car" ) as ? GraphQLObjectType
6667 assertNotNull(carType)
@@ -79,6 +80,19 @@ internal class PolymorphicTests {
7980 val personType = schema.getType(" Person" )
8081 assertNotNull(personType)
8182 }
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+ }
8296}
8397
8498class QueryWithInterface {
@@ -128,7 +142,7 @@ data class Arm(
128142 val value : Boolean
129143) : BodyPart
130144
131- class QueryWithInterfaceAnUnion {
145+ class QueryWithInterfaceAndUnion {
132146 fun product (): Product = Car (" DB9" , " black" )
133147}
134148
@@ -156,3 +170,16 @@ data class Father(
156170 val dadJoke : String ,
157171 override val child : Person ?
158172) : 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