Feature: GraphQL DSL Code Generation#249
Closed
kristileka wants to merge 5 commits intoairbnb:mainfrom
Closed
Conversation
Updating viaduct
… one that generates every other individual one. And each other generator is for different purposes. Mutation and Query dsl generators are used to generate the start point of the dsl for both of them, and the rest are nested deeper levels from graphql schema.
…enerated actually produce the bits of kotlin required
…ct Application plugin
rstata
approved these changes
Dec 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds a type-safe Kotlin DSL code generation system for GraphQL operations. It generates builder classes from GraphQL schemas, enabling compile-time safe query and mutation construction.
Description
Key Components
DSL Generators
Located in tenant/codegen/src/main/kotlin/viaduct/tenant/codegen/dsl/
DslFilesBuilder.kt | Main orchestrator that coordinates all generation and discovers types needing builders
QueryDslGenerator.kt | Generates query() function and QueryDslBuilder - scalar fields as properties, complex fields as functions
MutationDslGenerator.kt | Generates mutation() function and MutationDslBuilder - all fields as functions (reflects side-effect nature)
ObjectDslGenerator.kt | Generates {Type}DslBuilder classes for nested field selection
InputDslGenerator.kt | Generates {Input}Builder classes for input types, returning Map<String, Any?>
NodeInterfaceDslGenerator.kt | Generates interface builders with fragment methods (onUser(), onPost(), etc.)
OperationFieldDslGenerator.kt | Base generator for operation fields with input arguments
QueryFieldDslGenerator.kt / MutationFieldDslGenerator.kt | Specialized builders combining input args + selection sets
DslModelUtils.kt | Shared utilities for type mapping, parameter signatures, and serialization
CLI Command
tenant/codegen/src/main/kotlin/viaduct/tenant/codegen/cli/KotlinDslGenerator.kt
Plugin Integration
gradle-plugins/application-plugin/.../ViaductApplicationPlugin.kt
Configuration via ViaductApplicationExtension:
kotlinviaductApplication {
enableDsl.set(true) // default: false
dslPackageName.set("com.example.api.dsl")
}
How was it tested?
Test Coverage
Located in tenant/codegen/src/test/kotlin/viaduct/tenant/codegen/dsl/
10 test classes covering all generators: