Skip to main content

Configuration

The configuration is a superset of the existing configuration in graphql-codegen.

classConsolidationEnabled

Denotes whether to consolidate classes for input and output types whose fields are equivalent.

Default: true
Link: https://opensource.expediagroup.com/graphql-kotlin-codegen/docs/class-consolidation

dependentTypesInScope

Limits dependent types to include from onlyTypes list. Can be used to exclude classes that are imported from external packages.

If MyType depends on MyDependentType1 and MyDependentType2, we can allow MyDependentType2 to be imported externally by including its import in extraImports and omitting it in the dependentTypesInScope list.

Example

["MyType", "MyDependentType1"]

directiveReplacements

Denotes Kotlin annotations to replace GraphQL directives.

directive is the name of the directive to replace, and kotlinAnnotations is a list of Kotlin annotations to replace the directive with.

Use argumentsToRetain to forward arguments from the directive directly to the Kotlin annotation. Can be INT, FLOAT, STRING, BOOLEAN, or ENUM. @YourGraphQLDirective(arg1: "value1") -> @YourKotlinAnnotation(arg1 = "value1")

Use definitionType to apply the directive replacement to a specific kind of type definition. If omitted, the replacement will apply to all definition types.

Example

[{ directive: "myDirective", kotlinAnnotations: ['@MyAnnotation("some argument")'] }]

Example

[{ directive: "myDirective", definitionType: Kind.INPUT_OBJECT_TYPE_DEFINITION, kotlinAnnotations: ['@MyAnnotation("some argument")'] }]

externalUnionsAsInterfaces

Denotes Kotlin classes representing union types to be treated as interfaces rather than annotation classes.

This should be used for types outside dependentTypesInScope that are not generated by the plugin. Only use when unionGeneration is set to ANNOTATION_CLASS.

extraImports

Additional imports to add to the generated file. GraphQL Kotlin annotations are always imported.

Example

["com.example.additional.import.*"]

extraScalars

Additional scalars to add to the generated file. Unknown scalars default to String.

Example

[{ scalarName: "URL", kotlinType: "java.net.URL" }]

includeDependentTypes

Determines whether to generate dependent types from types listed in onlyTypes.

Default: true

onlyTypes

Only generate types matching those in this list. If empty, no types will be generated. If omitted, all types will be generated.

Example

["MyType", "MyEnum"]

packageName

The package name for the generated file.

Default: path.to.directory.containing.generated.file
Example

"com.example.generated"

resolverInterfaces

Denotes types that should be generated as interfaces rather than classes. Resolver classes should implement the interface functions to enforce a type contract.

Type names can be optionally passed with the classMethods config to generate the interface with suspend functions or java.util.concurrent.CompletableFuture functions. Pass nullableDataFetchingEnvironment: true to make the DataFetchingEnvironment argument nullable in each resolver function for that class.

Link: https://opensource.expediagroup.com/graphql-kotlin-codegen/docs/recommended-usage
Example

[
{
typeName: "MyResolverType",
},
{
typeName: "MySuspendResolverType",
classMethods: "SUSPEND",
},
{
typeName: "MyCompletableFutureResolverType",
classMethods: "COMPLETABLE_FUTURE",
},
{
typeName: "MyTypeWithNullableDataFetchingEnvironment",
nullableDataFetchingEnvironment: true,
}
]

unionGeneration

Denotes the generation strategy for union types. Can be ANNOTATION_CLASS or MARKER_INTERFACE.

The MARKER_INTERFACE option is highly recommended, since it is more type-safe than using annotation classes.

Default: MARKER_INTERFACE
Link: https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/writing-schemas/unions/