https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
j

Jilles van Gurp

01/14/2021, 7:05 PM
This page (https://expediagroup.github.io/graphql-kotlin/docs/schema-generator/writing-schemas/interfaces) suggests it should be possible to use sealed classes in our generated schema. However, I’ve not been able to make this work for us. Is this known broken in the current 4.0 alpa11 or is there something I’m missing here? I’m trying to add a field to one of our input types that is a simple sealed class. As soon as I do that, I get this error:
Copy code
Caused by: com.expediagroup.graphql.exceptions.CouldNotCastGraphQLSchemaElement: Could not cast GraphQLSchemaElement GraphQLInterfaceType{name='GeoJsonGeometry', description='null', fieldDefinitionsByName=[type], typeResolver=null} to class graphql.schema.GraphQLInputType
This is the sealed class
Copy code
sealed class GeoJsonGeometry(val type: GeometryType) {
    class Point(type: GeometryType = GeometryType.Point): GeoJsonGeometry(type)
    class Polygon(type: GeometryType = GeometryType.Polygon): GeoJsonGeometry(type)
}
Simply adding a
val geometry: GeoJsonGeometry?=null
to our input date class breaks it, removing that fixes it.
s

Shane Myrick

01/14/2021, 7:36 PM
Kotlin Sealed classes generate GraphQL interfaces and the GraphQL spec says that interfaces can not be used as input. So you will have to use the sealed class values as the types
j

Jilles van Gurp

01/15/2021, 9:42 AM
Right, so that's a limitation of the graphql type system then.
s

Shane Myrick

01/15/2021, 6:08 PM
I updated the docs here, as that info was missing: https://github.com/ExpediaGroup/graphql-kotlin/pull/1017
👍 1
3 Views