This project was created with:
sbt new scala/scala3.g8
We are going query GraphqlZero which is a free, online GraphQL API we can use to get fake data.
The GraphQL schema in this project was downloaded from GraphqlZero API
and saved as: src/main/graphql/graphqlzero.graphql
This project is configured with Caliban GraphQL Client.
The build.sbt
contains the necessary dependencies:
"com.github.ghostdogpr" %% "caliban-client" % "1.2.1"
The build.sbt
also enables the CalibanPlugin
:
.enablePlugins(CalibanPlugin)
The project/plugins.sbt
contains the CalibanPlugin
:
addSbtPlugin("com.github.ghostdogpr" % "caliban-codegen-sbt" % "1.3.0")
CalibanPlugin
allows you to generate the client code from a schema file or from a server URL.
Run this sbt
command to translate src/main/graphql/graphqlzero.graphql
into a Caliban-generated client library
saved in src/main/scala/graphqlzero/Client.scala
:
calibanGenClient src/main/graphql/graphqlzero.graphql src/main/scala/graphqlzero/Client.scala --genView true
The run
sbt command is going to run the main definition from src/main/scala/Main.scala
:
run
The application is going to output a simple query equivalent to the following GraphQL query against GraphqlZero API:
query {
album(id: 1) {
id
title
}
}