### Install GraphQL Kotlin Codegen (bun) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/getting-started.mdx Installs the GraphQL Kotlin Codegen package as a development dependency using bun. This is a fast package manager, suitable for projects that require quick installation of build tools. ```shell bun add -d @expediagroup/graphql-kotlin-codegen ``` -------------------------------- ### Install GraphQL Kotlin Codegen (npm) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/getting-started.mdx Installs the GraphQL Kotlin Codegen package as a development dependency using npm. This package is required for generating Kotlin code from GraphQL schemas. ```shell npm install -D @expediagroup/graphql-kotlin-codegen ``` -------------------------------- ### Install GraphQL Kotlin Codegen (pnpm) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/getting-started.mdx Installs the GraphQL Kotlin Codegen package as a development dependency using pnpm. This command ensures the necessary tools are available for generating Kotlin data classes and other artifacts from your GraphQL schema. ```shell pnpm add -D @expediagroup/graphql-kotlin-codegen ``` -------------------------------- ### Install GraphQL Kotlin Codegen (yarn) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/getting-started.mdx Installs the GraphQL Kotlin Codegen package as a development dependency using yarn. This package is essential for integrating schema-first GraphQL development into your Kotlin projects. ```shell yarn add -D @expediagroup/graphql-kotlin-codegen ``` -------------------------------- ### GraphQL Codegen Configuration (YAML) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/getting-started.mdx Configures graphql-codegen to use the GraphQL Kotlin Codegen plugin. This example specifies the schema location and the output file for generated Kotlin types, along with codegen-specific options like naming convention and package name. ```yaml 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 ``` -------------------------------- ### GraphQL Codegen Configuration (TypeScript) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/getting-started.mdx Sets up graphql-codegen using a TypeScript configuration file, enabling the GraphQL Kotlin Codegen plugin. This approach provides type safety for the configuration object and allows for dynamic configuration if needed. It mirrors the YAML configuration, specifying schema, output, and plugin-specific options. ```typescript 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; ``` -------------------------------- ### Install Dependencies with Bun Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/CONTRIBUTING.md Command to install project dependencies using Bun. This is a required step after cloning the repository to set up the development environment. ```shell bun install ``` -------------------------------- ### Format Commits for Semantic Release Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/CONTRIBUTING.md Example of the required commit message format for Semantic Release. This convention helps automate versioning and changelog generation. ```git commit (): ``` -------------------------------- ### GraphQL Schema Example with Field Arguments Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/inheritance.md This GraphQL schema defines a 'Query' type with a field 'resolveMyType' which returns a 'MyType'. The 'MyType' itself has a field 'resolveMe' that accepts a String argument and returns a String. ```graphql type Query { resolveMyType: MyType! } type MyType { resolveMe(input: String!): String! } ``` -------------------------------- ### GraphQL Schema Example for Class Consolidation Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/class-consolidation.md Demonstrates a GraphQL schema with equivalent UserInput and User types. These types have identical fields and will be consolidated by GraphQL Kotlin Codegen into a single Kotlin data class. ```graphql input UserInput { name: String! email: String! } type User { name: String! email: String! } ``` -------------------------------- ### Top Level Types Inheritance - Single Class Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/inheritance.md This example demonstrates how to handle top-level Query types when all resolvers are in a single class. It inherits from the generated 'Query' class and the specific Query interface. ```kotlin import com.expediagroup.graphql.server.operations.Query import com.types.generated.Query as QueryInterface class MyQuery : Query, QueryInterface() { override fun foo(): String = "Hello" override fun bar(): String = "World" } ``` -------------------------------- ### Top Level Types Inheritance - Multiple Classes (Conflict) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/inheritance.md This example shows a common issue when trying to separate Query resolvers into multiple classes by inheriting from the main generated 'Query' class. This leads to conflicts during schema generation due to duplicate field definitions. ```kotlin import com.expediagroup.graphql.server.operations.Query import com.types.generated.Query as QueryInterface class FooQuery : Query, QueryInterface() { override fun foo(): String = "Hello" } class BarQuery : Query, QueryInterface() { override fun bar(): String = "World" } ``` -------------------------------- ### Run Tests with Bun Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/CONTRIBUTING.md Command to execute all unit tests for the project using Bun. Tests are crucial for ensuring the stability of bug fixes and new functionality. ```shell bun test ``` -------------------------------- ### Implementing Resolvers with Default Data Classes Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/recommended-usage.md Shows how to implement GraphQL resolvers using the default generated data classes. This approach can be unperformant as all properties are initialized upon object creation, regardless of the queried fields. ```kotlin import com.expediagroup.graphql.server.operations.Query import com.types.generated.MyType import com.types.generated.Query as QueryInterface class MyQuery : Query, QueryInterface() { override fun resolveMyType(input: String): MyType = MyType( foo = myExpensiveCall1(), bar = myExpensiveCall2() ) } ``` -------------------------------- ### Optimized Kotlin Generation with Resolver Interfaces Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/recommended-usage.md Presents the optimized Kotlin code generated by graphql-kotlin-codegen when `resolverInterfaces` is configured. This approach generates open classes with function signatures, allowing for lazy resolution and improved performance. ```kotlin package com.types.generated open class Query { open fun resolveMyType(input: String): MyType = throw NotImplementedError("Query.resolveMyType must be implemented.") } open class MyType { open fun foo(): String = throw NotImplementedError("MyType.foo must be implemented.") open fun bar(): String? = throw NotImplementedError("MyType.bar must be implemented.") } ``` -------------------------------- ### Implementing Resolvers with Resolver Interfaces Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/recommended-usage.md Demonstrates how to implement GraphQL resolvers using the generated resolver interfaces. This method allows for independent and lazy resolution of fields, significantly improving performance for expensive operations. ```kotlin import com.expediagroup.graphql.server.operations.Query import com.types.generated.Query as QueryInterface import com.types.generated.MyType as MyTypeInterface class MyQuery : Query, QueryInterface() { override fun resolveMyType(input: String): MyType = MyType() } class MyType : MyTypeInterface() { override fun foo(): String = myExpensiveCall1() override fun bar(): String? = myExpensiveCall2() } ``` -------------------------------- ### Create Git Branch Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/CONTRIBUTING.md Command to create a new Git branch for feature development. This ensures that each new feature or issue is worked on in isolation. ```shell git checkout -b my-new-feature ``` -------------------------------- ### Default Kotlin Generation for GraphQL Types Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/recommended-usage.md Demonstrates the default Kotlin code generated by graphql-kotlin-codegen for GraphQL types when fields have no arguments. This results in data classes which can lead to performance issues due to eager initialization. ```kotlin package com.types.generated open class Query { open fun resolveMyType(input: String): MyType = throw NotImplementedError("Query.resolveMyType must be implemented.") } data class MyType( val foo: String, val bar: String? = null ) ``` -------------------------------- ### Codegen Configuration for Resolver Interfaces Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/recommended-usage.md Illustrates the configuration for graphql-kotlin-codegen to generate resolver interfaces instead of data classes for specific types. This optimization is achieved by setting the `resolverInterfaces` option in the codegen configuration. ```typescript import { GraphQLKotlinCodegenConfig } from "@expediagroup/graphql-kotlin-codegen"; export default { resolverInterfaces: [ { typeName: "MyType", }, ], } satisfies GraphQLKotlinCodegenConfig; ``` -------------------------------- ### Kotlin Data Class Generation for Consolidated Types Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/class-consolidation.md Shows the resulting Kotlin data class when GraphQL Kotlin Codegen consolidates equivalent UserInput and User types. This single class serves for both input and output purposes. ```kotlin data class User( val name: String, val email: String ) ``` -------------------------------- ### Nested Kotlin Data Class Generation with Consolidation Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/class-consolidation.md Presents the generated Kotlin data classes for a nested GraphQL schema where types are consolidated. Both 'Name' and 'User' types are generated as single data classes representing their consolidated input and output forms. ```kotlin data class User( val name: Name, val email: String ) data class Name( val first: String, val last: String ) ``` -------------------------------- ### Generated Kotlin Code for Schema Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/inheritance.md This Kotlin code is automatically generated by GraphQL Kotlin Codegen based on the provided GraphQL schema. It defines open classes for 'Query' and 'MyType' with abstract methods representing the schema fields, serving as a base for implementation. ```kotlin package com.types.generated open class Query { open fun resolveMyType(): MyType = throw NotImplementedError("Query.resolveMyType must be implemented.") } open class MyType { open fun resolveMe(input: String): String = throw NotImplementedError("MyType.resolveMe must be implemented.") } ``` -------------------------------- ### Kotlin Implementation of Generated Code Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/inheritance.md This Kotlin code provides the actual implementation for the generated GraphQL types. It inherits from the generated 'Query' and 'MyType' classes, overriding the abstract methods to provide the resolver logic. ```kotlin import com.expediagroup.graphql.server.operations.Query import com.types.generated.MyType as MyTypeInterface import com.types.generated.Query as QueryInterface class MyQuery : Query, QueryInterface() { override fun resolveMyType(): MyTypeInterface = MyType() } class MyType : MyTypeInterface() { override fun resolveMe(input: String): String = "Hello world!" } ``` -------------------------------- ### Nested Type Consolidation in GraphQL Schema Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/class-consolidation.md Illustrates a more complex GraphQL schema with nested types (UserInput, NameInput, User, Name). The class consolidation feature handles these nested structures recursively, consolidating NameInput/Name and UserInput/User. ```graphql input UserInput { name: NameInput! email: String! } input NameInput { first: String! last: String! } type User { name: Name! email: String! } type Name { first: String! last: String! } ``` -------------------------------- ### Top Level Types Inheritance - Multiple Classes (Corrected) Source: https://github.com/expediagroup/graphql-kotlin-codegen/blob/main/docs/docs/inheritance.md This is the correct approach for separating Query resolvers into multiple classes. It involves inheriting from field-level generated interfaces (e.g., 'FooQueryInterface', 'BarQueryInterface') instead of the main generated 'Query' class to avoid conflicts. ```kotlin import com.expediagroup.graphql.server.operations.Query import com.types.generated.FooQueryInterface import com.types.generated.BarQueryInterface class FooQuery : Query, FooQueryInterface() { override fun foo(): String = "Hello" } class BarQuery : Query, BarQueryInterface() { override fun bar(): String = "World" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.