https://kotlinlang.org logo
#kgraphql
Title
# kgraphql
i

itzik kasovitch

06/20/2022, 2:19 PM
Hi, I am trying to figure out if the following case is supported by KGraphQL. I need to write an api where the input is something like the composite design patter.. For keeping the API general I want the input type to be the type of the base class. When I try to do it I get a
Failed to coerce
exception. So the input type would be:
Copy code
sealed class Base {
    data class Leaf(val prop: Int): Base()
    data class Composite(val prop: List<Base>): Base()
}
I tried different kind of kotlinx.serialization annotations to make it work but it seems like behind the scenes it failed since Jackson is used. Also when I try to use the base as an
inputType
I get an error that it doesn't have any fields. I also tried to use the derived classes as
inputType
. Without success. Last, in the examples I can only see something which returns a unionType (not something the accepts a unionType).
j

jeggy

06/21/2022, 8:22 AM
Hi, this is currently not supported by the GraphQL spec. They are working on a specification of how this would work. And I think when it will get into the official spec, something like sealed class for a input type will be the perfect solution. https://github.com/graphql/graphql-spec/pull/825
i

itzik kasovitch

06/21/2022, 8:37 AM
Thanks @jeggy.
3 Views