Kotlin

Package nameWeekly DownloadsVersionLicenseUpdated
@graphql-codegen/kotlinDownloadsVersionLicenseApr 19th, 2026

Installation

npm i -D @graphql-codegen/kotlin

Config API Reference

package

type: string

Customize the Java package name. The default package name will be generated according to the output file path.

Usage Examples

generates:
  src/main/kotlin/my-org/my-app/Resolvers.kt:
    plugins:
      - kotlin
    config:
      package: custom.package.name

enumValues

type: unknown_1

Overrides the default value of enum values declared in your GraphQL schema.

listType

type: string default: Iterable

Allow you to customize the list type

Usage Examples

generates:
  src/main/kotlin/my-org/my-app/Types.kt:
    plugins:
      - kotlin
    config:
      listType: Map

withTypes

type: boolean default: false

Allow you to enable generation for the types

Usage Examples

generates:
  src/main/kotlin/my-org/my-app/Types.kt:
    plugins:
      - kotlin
    config:
      withTypes: true

omitJvmStatic

type: boolean default: false

Allow you to omit JvmStatic annotation

The kotlin plugin generates Kotlin classes for Enums and Input types.

You can use this plugin to generate Java enums based on your GraphQL schema, and it also generates a type-safe Kotlin transformer for GraphQL input types.

Prepare your environment

To get started with these plugins and preset, make sure you have the following installed:

  • Node.js (10 or later)
  • NPM or Yarn

Run the following in your Android project:

npm init --yes
npm install graphql
npm install -D @graphql-codegen/cli @graphql-codegen/kotlin

Then, create codegen.yml with the following configuration:

schema: POINT_TO_YOUR_SCHEMA
documents: POINT_TO_YOUR_GRAPHQL_OPERATIONS
generates:
  ./app/src/Types.kt:
    plugins:
      - kotlin
💡
Also, make sure to add node_modules to your .gitignore file.