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

Mattlangsenkamp

11/09/2020, 6:28 PM
How does one specify that a certain resolver returns I union type. I see how to define a type in the docs but not how to use it
j

jeggy

11/09/2020, 11:12 PM
Hi, Sorry for being so inactive the latetly. I will be more active in this project soon again 🙂 I have updated the docs for union types with a bit more example code: https://kgraphql.io/Reference/Type%20System/unions/ Currently there is one common use case that is not supported which is using non sealed classes union types within query definitions. Other than this everything should work.
m

Mattlangsenkamp

11/10/2020, 12:07 AM
I see. I am trying to return either the error or an object based on the union type above. However when I build I still get this error.
j

jeggy

11/10/2020, 12:10 AM
these screenshots do not show where you are trying to return your union type. But by the error you are getting it seems you are using the
query
. Which I mentioned currently is not supported 😞
m

Mattlangsenkamp

11/10/2020, 12:11 AM
sorry here us the full operation
it is a mutation and I am trying to return the encodedTokens if they are not null otherwise the errorMessage
j

jeggy

11/10/2020, 12:15 AM
Sorry I mean both
query
and
mutation
are not supported as they are both using the same DSL implementation. Currently a workaround is required to make something like this work. Which is to change the
EncodedTokens
and
ServerError
to a Kotlin Sealed class.
5 Views