GraphQL Kotlin supports generation of client data models that are compatible with both
Jackson (default) and
formats. Build plugins and
graphql-kotlin-spring-client default to use
See client serialization documentation for additional details.
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 models
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
__UNKNOWN_VALUE 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 generic interface that exposes
execute methods that will suspend your GraphQL operation until
it gets a response back without blocking the underlying thread. Reference Ktor and Spring WebClient based implementations
offer fully asynchronous communication through Kotlin coroutines. In order to fetch data asynchronously you should wrap
your client execution in
async coroutine builder and explicitly
await for their results.
See Kotlin coroutines documentation for additional details.
GraphQL Kotlin Clients provide out of the box support for batching multiple client operations into a single GraphQL request. Batch requests are sent as an array of individual GraphQL requests and clients expect the server to respond with a corresponding array of GraphQL responses. Each response is then deserialized to a corresponding result type.