Overview
Theserve task provides a development server for Viaduct applications with built-in GraphiQL IDE and automatic code reloading. This is the fastest way to iterate during development.
Features
- GraphiQL IDE: Interactive GraphQL explorer in your browser
- Auto-reloading: Automatic rebuild and restart when code changes
- Zero configuration: Works out-of-the-box for simple applications
- Hot reload: Changes reflected immediately without manual restart
Prerequisites
Theserve task is automatically available in any project that applies the Viaduct application plugin:
Quick Start
Start with Auto-Reload (Recommended)
Start the development server with automatic reloading:- Gradle detects the change
- Rebuilds the affected code
- Restarts the server automatically
- GraphQL endpoint:
http://localhost:8080/graphql - GraphiQL IDE:
http://localhost:8080/graphiql - Health check:
http://localhost:8080/health
Ctrl+C to stop.
Start Without Auto-Reload
If you need to run the server without auto-reloading:Configuration
In build.gradle.kts (Recommended)
Configure serve settings using theviaductApplication extension:
modulePackagePrefix: Package prefix for discovering your resolvers (used in default mode)servePort: Port for the development server (default: 8080)serveHost: Host to bind to (default: 0.0.0.0, accessible from any interface)
Using Gradle Properties (Override)
You can override these settings at runtime:gradle.properties file:
Dependency Injection
Using @ViaductServerConfiguration
To enable dependency injection in your resolvers, create a class annotated with@ViaductServerConfiguration that implements ViaductFactory:
Example: Micronaut Integration
Example: Manual Configuration
Without @ViaductServerConfiguration (Default Mode)
If no@ViaductServerConfiguration annotated class is found, the serve server falls back to default mode using viaductApplication.modulePackagePrefix from your build configuration.
Limitations in default mode:
- Dependency injection is NOT available
- Only
@Resolverclasses with zero-argument constructors work - Resolvers requiring injected dependencies will fail
@ViaductServerConfiguration class.
Development Workflow
Recommended Workflow
-
Start the server in continuous mode:
-
Open GraphiQL in your browser:
http://localhost:8080/graphiql -
Make changes to your schema or resolvers:
- Gradle automatically detects the change, rebuilds, and restarts the server
- Refresh GraphiQL to see the new field in the schema
What Gets Watched
Continuous mode watches:- GraphQL schema files (
.graphqls) in all modules - Kotlin source files in
src/main/kotlin - Resource files referenced by the application
- Build configuration (when relevant)
Using GraphiQL
GraphiQL provides an interactive environment for exploring and testing your GraphQL API.Accessing GraphiQL
Open your browser to:Features
- Query Editor: Write and execute GraphQL queries with syntax highlighting
- Schema Documentation: Browse your schema’s types, fields, and descriptions
- Auto-completion: Get suggestions as you type queries
- Query History: Access previously executed queries
- Variables Panel: Test queries with different variable values
- Response Viewer: Formatted JSON response display
Example Query
Try this query in GraphiQL:Testing with Variables
Use the variables panel to test queries with parameters: Query:Testing Mutations
Troubleshooting
Port Already in Use
If port 8080 is already in use: Option 1: Stop the process using the portServer Not Restarting in Continuous Mode
If the server doesn’t restart after changes:-
Check you’re using
--continuousflag -
Verify your changes are in watched files
- Schema files (
.graphqls) - Kotlin source files (
src/main/kotlin) - Not configuration files outside the project
- Schema files (
-
Check Gradle output for compilation errors
- Look for error messages in the terminal
- Fix any compilation errors
-
Try stopping and restarting
- Press
Ctrl+Cto stop - Run
./gradlew --continuous serveagain
- Press
Changes Not Reflected in GraphiQL
If code changes don’t appear:-
Hard refresh your browser
- Mac:
Cmd+Shift+R - Windows/Linux:
Ctrl+Shift+F5
- Mac:
-
Check the Gradle output
- Look for “Starting Viaduct Development Server…” in logs
- Verify the server actually restarted
-
Clear browser cache
- GraphiQL may cache schema information
Resolver Instantiation Errors
If you see errors about resolvers failing to instantiate:@ViaductServerConfiguration class to enable DI:
Package Prefix Not Found
If you see:modulePackagePrefix in your build.gradle.kts:
Comparison with Production
Theserve task is for development only. Key differences from production:
| Feature | Development Server | Production |
|---|---|---|
| HTTP Server | Built-in Jetty | Your choice (Jetty, Ktor, etc.) |
| Configuration | Minimal/automatic | Full control |
| Authentication | None | Custom implementation |
| Authorization | None | Custom implementation |
| Error Handling | Basic | Production-grade |
| Monitoring | None | Metrics, logging, tracing |
| Performance | Development mode | Optimized |
| Scalability | Single instance | Load balanced |
| Auto-reload | Yes | No |
| GraphiQL | Included | Optional |
- Configure your actual HTTP server (Ktor, Jetty, etc.)
- Set up proper authentication and authorization
- Configure production logging and monitoring
- Review the Production Deployment documentation
Next Steps
Embedding Viaduct
Learn how to integrate Viaduct into your HTTP server
Production Deployment
Production considerations and best practices
Testing
Learn how to test your Viaduct application
Resolvers
Write business logic in resolvers