Overview
Embedding Viaduct into your HTTP server is the recommended approach for production deployments. This gives you full control over HTTP handling, authentication, routing, and integration with your existing infrastructure. The core integration pattern is simple:- Create a Viaduct instance at application startup
- Create an HTTP route that accepts GraphQL requests
- Call
viaduct.execute()orviaduct.executeAsync()with the request - Return the result to the client
Creating a Viaduct Instance
Using BasicViaductFactory (Recommended)
For most applications, useBasicViaductFactory which provides sensible defaults:
tenantPackagePrefix: The package prefix where your resolvers and GraphQL modules are locatedschemaRegistrationInfo: Optional schema configuration for multi-tenant or scoped schemastenantCodeInjector: Optional dependency injection integration (defaults to reflection with zero-arg constructors)
Using ViaductBuilder (Advanced)
For fine-grained control over error reporting, metrics, and other SPI implementations:service/api/src/main/kotlin/viaduct/service/api/Viaduct.kt:1 for the full API.
Executing GraphQL Operations
Viaduct provides two execution methods:Synchronous Execution
Asynchronous Execution (Recommended)
HTTP Server Integration Examples
Jetty Example
A complete example using Eclipse Jetty servlets:demoapps/jetty-starter/src/main/kotlin/com/example/viadapp/JettyViaductApp.kt:1.
Ktor Example
Integrating with Ktor using coroutines:demoapps/ktor-starter/src/main/kotlin/com/example/viadapp/Routing.kt:1.
Micronaut Example
Using Micronaut’s dependency injection with Viaduct: ViaductConfiguration.kt - Creating the Viaduct bean:demoapps/starwars/src/main/kotlin/com/example/starwars/service/viaduct/ViaductConfiguration.kt:1demoapps/starwars/src/main/kotlin/com/example/starwars/service/viaduct/ViaductRestController.kt:1
Dependency Injection Integration
By default, Viaduct uses reflection to instantiate resolvers with zero-argument constructors. To integrate with a dependency injection framework, provide a customTenantCodeInjector:
Request Context
You can pass request-specific context (like authentication info) throughExecutionInput:
DataFetchingEnvironment:
Multi-Schema Support
Viaduct supports multiple schemas with different scope configurations:Error Handling
Handle execution errors appropriately:Next Steps
Development Server
Learn about the built-in development server
Production Deployment
Production considerations and best practices