Skip to content

Instantly share code, notes, and snippets.

@ghostdogpr
Last active February 8, 2020 00:06
Show Gist options
  • Save ghostdogpr/882dba4b43987b57a7dc21e2fff0dc12 to your computer and use it in GitHub Desktop.
Save ghostdogpr/882dba4b43987b57a7dc21e2fff0dc12 to your computer and use it in GitHub Desktop.
Early draft for caliban-client. Feedback welcome!
// Step 1:
// Code generation creates helpers from a GraphQL schema
// Character.* and Queries.* here are auto-generated
// Step 2:
// Build your own queries combining those helpers
val character =
(Character.name ~
Character.nicknames ~
Character.origin).mapN(CharacterView)
val query =
Queries.character("Amos Burton") {
character
}
case class CharacterView(name: String, nickname: List[String], origin: Origin)
// Step 3:
// Turn the query into an sttp request and run it with the sttp backend of your choice
// GraphQL result is already parsed and in the proper type
AsyncHttpClientZioBackend().flatMap { implicit backend =>
val request: Task[Option[CharacterView]] =
query.toRequest(uri).send().map(_.body).absolve
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment