Overview of GraphQL Kotlin
mastergraphql-java designed to simplify the implementation of GraphQL clients and servers in Kotlin. It provides tools for code-first schema generation, custom instrumentations, and lightweight HTTP clients.repository·master·Indexed 23 days ago
https://github.com/expediagroup/graphql-kotlinA suite of libraries for building GraphQL clients and servers in Kotlin leveraging graphql-java. It features a code-first schema generator and provides type-safe HTTP clients with native Kotlin Coroutines support. The library offers reference implementations for Ktor (graphql-kotlin-ktor-client) and Spring WebClient (graphql-kotlin-spring-client), with serialization support for both Jackson and kotlinx.serialization. It includes Gradle and Maven plugins for auto-generating Kotlin data models from GraphQL queries and schemas via introspection.
graphql-java designed to simplify the implementation of GraphQL clients and servers in Kotlin. It provides tools for code-first schema generation, custom instrumentations, and lightweight HTTP clients.The graphql-kotlin-gradle-plugin provides several tasks for schema generation and client creation. By default, these tasks are lazily registered and only instantiated when explicitly requested or when configured via the graphql extension. All tasks are prefixed with graphql and grouped under the GraphQL task group.
To view all available tasks, run:
$ gradle tasks --group graphqlAvailable Tasks:
graphqlDownloadSDL: Download schema in SDL format from a target endpoint.graphqlGenerateClient: Generate an HTTP client from specified GraphQL queries.graphqlGenerateSDL: Generate GraphQL schema in SDL format from source code.graphqlGenerateTestClient: Generate an HTTP test client from specified GraphQL queries.graphqLGraalVmMetadata: Generate GraalVM reflect metadata for servers.graphqlIntrospectSchema: Run introspection against an endpoint to save the schema locally.The GraphQL Kotlin Maven Plugin allows you to automate the generation of a lightweight GraphQL HTTP client and the generation of GraphQL schemas directly from your source code.
Important Requirement: This plugin depends on the Kotlin compiler plugin because it generates Kotlin source code that must subsequently be compiled by your build process.
The graphql-kotlin-client module provides an interface for lightweight, type-safe GraphQL HTTP clients. It is designed to work alongside GraphQL Kotlin build plugins that automatically generate type-safe Kotlin data models from your GraphQL queries. While you could manually create data models and perform simple POST requests, the intended usage pattern is to leverage the auto-generation capabilities to ensure type safety between your queries and your Kotlin code.
Key features include:
kotlinx.serialization and Jackson.String).GraphQL Kotlin provides lightweight, type-safe GraphQL HTTP clients. It offers reference implementations based on Ktor HTTP client and Spring WebClient, while allowing for custom implementations.
Key features include:
kotlinx.serialization and Jackson.String).graphql-kotlin-server module provides the foundational, framework-agnostic code required to build a GraphQL server. It defines common interfaces that allow you to implement GraphQL capabilities without being tied to a specific server library or web framework. This abstraction allows for flexibility when integrating with different underlying server technologies.graphql-kotlin-federated-hooks-provider module provides a default implementation of SchemaGeneratorHooksProvider. This is used to generate federated GraphQL schemas in SDL (Schema Definition Language) format. When used, it automatically creates a default instance of FederatedSchemaGeneratorHooks to handle the requirements of Apollo Federation within your schema generation process.The integration/federation-compatibility project serves as a reference implementation to verify that graphql-kotlin correctly adheres to the Apollo Federation Subgraph Specification.
It uses a specific reference schema containing advanced Federation v2.0 directives such as @key, @external, @provides, @requires, @shareable, @override, and @inaccessible. This implementation is used to ensure that the generated GraphQL schemas and the resulting execution behavior are compatible with Apollo Federation gateways.
The graphql-kotlin-schema-generator supports type system (schema) directives. It does not support executable (query) directives for schema generation, though standard query directives like @skip and @include are part of the GraphQL spec for runtime use.
@deprecated: Used to mark portions of the schema as deprecated. Use the @Deprecated or @GraphQLDeprecated annotation in Kotlin.@skip(if: Boolean): Allows conditional exclusion of fields or fragments.@include(if: Boolean): Allows conditional inclusion of fields or fragments.type Query {
deprecatedQuery: Boolean! @deprecated(reason: "No longer supported")
}
query myQuery($shouldSkip: Boolean) {
myField @skip(if: $shouldSkip)
}
query myQuery($shouldInclude: Boolean) {
myField @include(if: $shouldInclude)
}The graphql-kotlin-client-serialization library provides a serializer/deserializer abstraction for GraphQL clients using kotlinx.serialization. It handles the logic for converting GraphQL requests and responses, allowing clients to work with raw Strings for POST requests.
Important Requirement:
To use this library, you must configure the corresponding kotlinx.serialization compiler plugin in your project. Refer to the official kotlinx.serialization documentation for setup instructions.
The graphql-kotlin-gradle-plugin provides automation for several GraphQL-related tasks:
graphql-kotlin-client-generator module contains the core logic for generating type-safe GraphQL clients. Note: This module is not intended to be consumed directly as a dependency. Instead, you should use the official GraphQL Kotlin Gradle or Maven plugins to trigger code generation during your build process.