GraphQL supports polymorphic types through unions and interfaces which can be represented in Kotlin as marker and
regular interfaces. In order to ensure generated objects are not empty, GraphQL queries referencing polymorphic types
have to explicitly specify all implementations. Polymorphic queries also have to explicitly request
field so it can be used to Jackson correctly distinguish between different implementations.
Given example schema
We can query interface field as
Which will generate following data model
Enums represent predefined set of values. Adding additional enum values could be a potentially breaking change as your
clients may not be able to process it. GraphQL Kotlin Client automatically adds default
to all generated enums as a catch all safeguard for handling new enum values.
GraphQL Kotlin build plugins automatically pull in GraphQL descriptions of the queried fields from the target schema and add it as KDoc to corresponding data models.
Given simple GraphQL object definition
Will result in a corresponding auto generated data class
GraphQL Kotlin Client is a thin wrapper on top of Ktor HTTP Client which provides
fully asynchronous communication through Kotlin coroutines.
GraphQLClient exposes single
execute method that will
suspend your GraphQL operation until it gets a response back without blocking the underlying thread. In order to fetch
data asynchronously and perform some additional computations at the same time you should wrap your client execution in
async coroutine builder and explicitly
await for their results.
See Kotlin coroutines documentation for additional details.