Kotlin
Kotlin plugin for GraphQL Code Generator. Generate Kotlin classes for Enums and Input types.
- Package
- @graphql-codegen/kotlin
- Version
- 5.0.0
- Weekly downloads
- 11k
- License
- MIT
- Updated
- Nov 11, 2026
Installation
npm i -D @graphql-codegen/kotlin
yarn add -D @graphql-codegen/kotlin
pnpm add -D @graphql-codegen/kotlin
bun add -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: object
Overrides the default value of enum values declared in your GraphQL schema.
listType
type: string
Allow you to customize the list type Default value: “Iterable”
Usage Examples
generates:
src/main/kotlin/my-org/my-app/Types.kt:
plugins:
- kotlin
config:
listType: Map
withTypes
type: boolean
Allow you to enable generation for the types Default value: “false”
Usage Examples
generates:
src/main/kotlin/my-org/my-app/Types.kt:
plugins:
- kotlin
config:
withTypes: true
omitJvmStatic
type: boolean
Allow you to omit JvmStatic annotation Default value: “false”
strictScalars
type: boolean
Makes scalars strict.
If scalars are found in the schema that are not defined in scalars
an error will be thrown during codegen.
Default value: “false”
Usage Examples
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
strictScalars: true,
},
},
},
};
export default config;
defaultScalarType
type: string
Allows you to override the type that unknown scalars will have. Default value: “unknown”
Usage Examples
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
defaultScalarType: 'any'
},
},
},
};
export default config;
scalars
type: object
Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
namingConvention
type: object
Allow you to override the naming convention of the output.
You can either override all namings, or specify an object with specific custom naming convention per output.
The format of the converter must be a valid module#method.
Allowed values for specific output are: typeNames, enumValues.
You can also use “keep” to keep all GraphQL names as-is.
Additionally, you can set transformUnderscore to true if you want to override the default behavior,
which is to preserve underscores.
Available case functions in change-case-all are camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase, lowerCase, localeLowerCase, lowerCaseFirst, spongeCase, titleCase, upperCase, localeUpperCase and upperCaseFirst
See more
Default value: “change-case-all#pascalCase”
typesPrefix
type: string
Prefixes all the generated types. Default value: ""
Usage Examples
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
typesPrefix: 'I',
},
},
},
};
export default config;
typesSuffix
type: string
Suffixes all the generated types. Default value: ""
Usage Examples
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
typesSuffix: 'I',
},
},
},
};
export default config;
enumPrefix
type: boolean
Allow you to disable prefixing for generated enums, works in combination with typesPrefix.
Default value: “true”
Usage Examples
Disable enum prefixes
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
typesPrefix: 'I',
enumPrefix: false
},
},
},
};
export default config;
enumSuffix
type: boolean
Allow you to disable suffixing for generated enums, works in combination with typesSuffix.
Default value: “true”
Usage Examples
Disable enum suffixes
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
typesSuffix: 'I',
enumSuffix: false
},
},
},
};
export default config;
useTypeImports
type: boolean
Will use import type {} rather than import {} when importing only types. This gives
compatibility with TypeScript’s “importsNotUsedAsValues”: “error” option
Default value: “false”
Usage Examples
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'path/to/file': {
// plugins...
config: {
useTypeImports: true
},
},
},
};
export default config;
inlineFragmentTypes
type: string
Whether fragment types should be inlined into other operations. “inline” is the default behavior and will perform deep inlining fragment types within operation type definitions. “combine” is the previous behavior that uses fragment type references without inlining the types (and might cause issues with deeply nested fragment that uses list types). “mask” transforms the types for use with fragment masking. Useful when masked types are needed when not using the “client” preset e.g. such as combining it with Apollo Client’s data masking feature. Default value: “inline”
importExtension
type: object
Append this extension to all imports. Useful for ESM environments that require file extensions in import statements.
printFieldsOnNewLines
type: boolean
If you prefer to have each field in generated types printed on a new line, set this to true. This can be useful for improving readability of the resulting types, without resorting to running tools like Prettier on the output. Default value: “false”
includeExternalFragments
type: boolean
Whether to include external fragments in the generated code. External fragments are not defined in the same location as the operation definition. Default value: “false”
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:
Then, create codegen.yml with the following configuration: