Skip to main content
Version: ZIO 2.x

ZIO Quickstart: Building GraphQL Web Service

This quickstart shows how to build a GraphQL web service using ZIO. It uses

Creating GraphQL API using Caliban is an easy process. We can define our data models using case classes and ADTs. Then Caliban can derive the whole GraphQL schema from these data models.

Running The Example

First, open the console and clone the project using git (or you can simply download the project) and then change the directory:

git clone git@github.com:zio/zio-quickstart-graphql-webservice.git 
cd zio-quickstart-graphql-webservice

Once you are inside the project directory, run the application:

sbt run

Testing The Quickstart

In this project, we have defined models of our employees with their names and roles. Then using GraphQL annotations, we asked Caliban to derive the GraphQL schema from these models.

So we can query all the employees that are software developers using the GraphQL query:

query{
employees(role: SoftwareDeveloper){
name
role
}
}

To run this query, we can use any of the GraphGL clients or use the following curl command:

curl 'http://localhost:8088/api/graphql' --data-binary '{"query":"query{\n employees(role: SoftwareDeveloper){\n name\n role\n}\n}"}'

The response will be as follows:

{
"data" : {
"employees" : [
{
"name" : "Maria",
"role" : "SoftwareDeveloper"
},
{
"name" : "Peter",
"role" : "SoftwareDeveloper"
}
]
}
}