Skip to content

Feature: GraphQL DSL Code Generation#249

Closed
kristileka wants to merge 5 commits intoairbnb:mainfrom
kristileka:feature/adds-schema-dsl-generator
Closed

Feature: GraphQL DSL Code Generation#249
kristileka wants to merge 5 commits intoairbnb:mainfrom
kristileka:feature/adds-schema-dsl-generator

Conversation

@kristileka
Copy link
Copy Markdown
Collaborator

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:

kristileka and others added 5 commits December 16, 2025 17:47
… 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
@rstata rstata closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants