Doc type: Reference
This is a sample GraphQL application built using Viaduct, a composable GraphQL server in Kotlin.
This app models the Star Wars universe with characters, films, species, planets, and starships. It demonstrates how to implement resolvers, field-level context, pagination, fragments, and mock data using Viaduct’s conventions.
- Java JDK 21
JAVA_HOMEis correctly set, orjavais available in yourPATH
./gradlew runThis will start the server at http://localhost:8080.
Open your browser and go to GraphiQL interface:
http://localhost:8080/graphiql
query {
allCharacters(limit: 5) {
id
name
homeworld {
name
}
}
}The ViaductGraphQLController.kt applies scope metadata from the X-Viaduct-Scopes header into the GraphQL context.
Some fields—like Species.culturalNotes are marked with @scope(to: ["extras"]). These will only resolve if the "extras" scope is present in the context.
Use a query like:
query {
node(id: "U3BlY2llczox") {
... on Species {
name
culturalNotes
specialAbilities
}
}
}In GraphiQL, add this to the Headers tab below the query pane:
{
"X-Viaduct-Scopes": "extras"
}Run a complex character query with batch‑resolved fields.
query {
allCharacters(limit: 3) {
name
homeworld { name }
species { name }
filmCount
richSummary
}
}Fields such as
filmCountandrichSummaryare computed by Character resolvers. @SeeCharacterResolvers.kt,SpeciesBatchResolver.ktandFilmCountBatchResolver.kt.
Resolution is batched by Viaduct’s resolver execution model (and/or DataLoaders if configured), which helps avoid N+1 patterns when the query asks these derived fields across multiple characters.
Query films with their main characters
query {
allFilms {
title
director
mainCharacters {
name
homeworld { name }
}
}
}A central concept in Viaduct is the Node: any object retrievable by a globally unique ID. Every Node has an id field.
Internally, a Viaduct ID consists of as base64-encoded string :
TypeName:LocalId
For example:
Character:5 → "Q2hhcmFjdGVyOjU="
In GraphiQL you can use the key icon in the toolbar (🔑) to encode or decode these IDs.
query {
node(id: "Q2hhcmFjdGVyOjU=") {
... on Character {
name
homeworld {
id
}
}
}
}Returns:
{
"data": {
"node": {
"name": "Obi-Wan Kenobi",
"homeworld": {
"id": "UGxhbmV0OjQ="
}
}
}
}You request the identifier UGxhbmV0OjQ= as a node query to retrieve the name of this planet:
query {
node(id: "UGxhbmV0OjQ=") {
... on Planet {
name
}
}
}If you decode the id from base64, you can notice that the id
UGxhbmV0OjQ=is decoded to"Planet:4".
Which returns:
{
"data": {
"node": {
"name": "Stewjon"
}
}
}For a deeper technical explanation of how the system works, see the Getting Started Guide.