graphql-kotlin

repository·master·Indexed 23 days ago

https://github.com/expediagroup/graphql-kotlin

A 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.

Tokens
100.1K
Snippets
249
Records
406
Agent score
79%

What's inside graphql-kotlin

  1. Overview of GraphQL Kotlin

    master
    GraphQL Kotlin is a collection of libraries built on top of 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.
  2. Overview of graphql-kotlin-gradle-plugin tasks

    master

    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 graphql

    Available 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.
  3. Overview of GraphQL Kotlin Maven Plugin functionality

    master

    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.

  4. Overview of GraphQL Kotlin Client

    master

    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:

    • Support for queries, mutations, and batch operations.
    • Automatic generation of models supporting kotlinx.serialization and Jackson.
    • Native support for Kotlin Coroutines.
    • Custom scalar support (defaults to String).
    • Support for default enum values to handle unknown server values gracefully.
    • Integration with Ktor and Spring WebClient-based HTTP clients.
  5. Overview of GraphQL Kotlin Clients

    master

    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:

    • Support for query, mutation, and batch operations.
    • Automatic generation of type-safe Kotlin models supporting kotlinx.serialization and Jackson.
    • Custom scalar support (defaults to String).
    • Support for default enum values to handle unknown server values.
    • Native support for coroutines.
    • Documentation generated from the underlying GraphQL schema.
  6. Overview of GraphQL Kotlin Server

    master
    The 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.
  7. Use GraphQL Kotlin Federated Hooks Provider for SDL generation

    master
    The 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.
  8. Understand Apollo Federation Subgraph Compatibility testing

    master

    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.

  9. Supported GraphQL Directives

    master

    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.

    Default Schema Directives

    • @deprecated: Used to mark portions of the schema as deprecated. Use the @Deprecated or @GraphQLDeprecated annotation in Kotlin.

    Standard Query Directives

    • @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)
    }
  10. Use GraphQL Kotlin Client with kotlinx.serialization

    master

    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.

  11. What does the GraphQL Kotlin Gradle Plugin do?

    master

    The graphql-kotlin-gradle-plugin provides automation for several GraphQL-related tasks:

    1. Schema Introspection & SDL Generation: Introspect existing GraphQL servers or generate SDL (Schema Definition Language) files from GraphQL Kotlin servers.
    2. Client Generation: Generate a lightweight GraphQL HTTP client based on your schema.
    3. GraalVM Support: Generate GraalVM reachability metadata for GraphQL Kotlin servers to facilitate native image compilation.
    4. Schema Processing: Identify and process packages containing GraphQL schema type definitions.