Back to Graphql Code Generator

kotlin

website/src/pages/plugins/java/kotlin.mdx

1.17.71.1 KB
Original Source

import { Callout } from '@theguild/components' import { PluginApiDocs, PluginHeader } from '@/components/plugin' import { pluginGetStaticProps } from '@/lib/plugin-get-static-props' export const getStaticProps = pluginGetStaticProps(__filename)

<PluginHeader />

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:

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

Then, create codegen.yml with the following configuration:

yaml
schema: POINT_TO_YOUR_SCHEMA
documents: POINT_TO_YOUR_GRAPHQL_OPERATIONS
generates:
  ./app/src/Types.kt:
    plugins:
      - kotlin

<Callout>Also, make sure to add node_modules to your .gitignore file.</Callout>

<PluginApiDocs />