This page (<https://expediagroup.github.io/graphql...
# graphql-kotlin
j
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
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
Right, so that's a limitation of the graphql type system then.
s
I updated the docs here, as that info was missing: https://github.com/ExpediaGroup/graphql-kotlin/pull/1017
👍 1