Last active
February 8, 2020 00:06
-
-
Save ghostdogpr/882dba4b43987b57a7dc21e2fff0dc12 to your computer and use it in GitHub Desktop.
Early draft for caliban-client. Feedback welcome!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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