Getting Started
GraphQL Kotlin Codegen is a plugin for graphql-codegen that generates Kotlin code from Schema Definition Language (SDL). This Kotlin code is meant to be consumed by services using GraphQL Kotlin and allows SDL to drive the implementation of your schema. In essence, it unlocks a schema-first approach to code-first GraphQL.
Installation
- npm
- yarn
- pnpm
- bun
npm install -D @expediagroup/graphql-kotlin-codegen
yarn add -D @expediagroup/graphql-kotlin-codegen
pnpm add -D @expediagroup/graphql-kotlin-codegen
bun add -d @expediagroup/graphql-kotlin-codegen
Usage
Example codegen.yml
:
schema:
- "path/to/**/*.graphql"
generates:
output/Types.kt:
plugins:
- "@expediagroup/graphql-kotlin-codegen":
namingConvention: "keep" # graphql-codegen config
packageName: "com.example" # graphql-kotlin-codegen config
Example codegen.ts
:
import { CodegenConfig } from "@graphql-codegen/cli";
import { GraphQLKotlinCodegenConfig } from "@expediagroup/graphql-kotlin-codegen";
export default {
schema: "path/to/**/*.graphql",
generates: {
"output/Types.kt": {
plugins: [
{
"@expediagroup/graphql-kotlin-codegen": {
namingConvention: "keep", // graphql-codegen config
packageName: "com.example", // graphql-kotlin-codegen config
} satisfies GraphQLKotlinCodegenConfig,
},
],
},
},
} satisfies CodegenConfig;