This guide walks you through setting up a new Viaduct tenant project, including the proper Gradle configuration, module structure, and directory layout.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/airbnb/viaduct/llms.txt
Use this file to discover all available pages before exploring further.
Project Structure
A typical Viaduct project follows a modular architecture:Viaduct uses a modular architecture where each domain area (users, orders, etc.) is a separate Gradle module with its own schema and resolvers.
Gradle Plugins
Viaduct provides two Gradle plugins:Application Plugin
Apply to your root application module:build.gradle.kts
Package name for generated GraphQL Representational Types (GRTs)
Base package for your application modules (e.g.,
com.example.myapp)Module Plugin
Apply to each tenant module:modules/users/build.gradle.kts
Suffix for this module’s package (combined with
modulePackagePrefix)Complete Application Setup
Create the application build file
Create
build.gradle.kts for your main application:build.gradle.kts
Configure multi-module settings
Create
settings.gradle.kts to define your modules:settings.gradle.kts
Create the schema directory
Create the schema directory structure:Add your GraphQL schema file:
modules/users/src/main/viaduct/schema/User.graphqls
Schema files must be placed in
src/main/viaduct/schema/ with the .graphqls extension.Create resolver directory
Create the Kotlin source directory:Your resolver classes will go here (covered in Writing Resolvers).
Version Catalog Setup
Use Gradle’s version catalog for dependency management:gradle/libs.versions.toml
Directory Conventions
Schema Files
- Location:
src/main/viaduct/schema/ - Extension:
.graphqls - Pattern: One file per type is recommended (e.g.,
User.graphqls,Order.graphqls)
Resolver Files
- Location:
src/main/kotlin/<package>/resolvers/ - Naming: Descriptive names like
UserNodeResolver.kt,OrdersQueryResolver.kt - Package: Follows your
modulePackagePrefix+modulePackageSuffix
Generated Code
Viaduct generates code inbuild/generated/:
- GRTs:
viaduct.api.grtspackage - Resolver bases:
<modulePackagePrefix>.<suffix>.resolverbasespackage
Building Your Project
--continuous flag enables auto-reload when you change schema or resolver files.
Common Module Pattern
Create a common module for shared utilities:common/build.gradle.kts
common/src/main/kotlin/com/example/myapp/common/Context.kt
Integration Examples
With Ktor
src/main/kotlin/Application.kt
With Micronaut
src/main/kotlin/GraphQLController.kt
Next Steps
Defining Schemas
Learn how to write GraphQL schemas with Viaduct directives
Writing Resolvers
Implement field and node resolvers for your schema
Troubleshooting
Build fails with 'unresolved reference' errors
Build fails with 'unresolved reference' errors
Ensure you have:
- Applied the correct Gradle plugins (
viaduct.applicationorviaduct.module) - Created schema files in
src/main/viaduct/schema/ - Run
./gradlew buildto generate GRTs
Schema files not being picked up
Schema files not being picked up
Check that:
- Files are in
src/main/viaduct/schema/directory - Files have
.graphqlsextension - You’ve run a Gradle build after creating them
Module package prefix issues
Module package prefix issues
Ensure
modulePackagePrefix in the application matches the package structure of your modules.Example: If prefix is com.example.myapp and module suffix is users, your resolvers should be in com.example.myapp.users.*