Last active
June 28, 2024 06:25
-
-
Save ghostdogpr/7eaf3d6b38a78a3a55723954f4fa9ba6 to your computer and use it in GitHub Desktop.
Caliban + Ox demo
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
//> using dep com.github.ghostdogpr::caliban-tapir:2.8.0 | |
//> using dep com.softwaremill.ox::core:0.2.2 | |
//> using dep com.softwaremill.sttp.tapir::tapir-jsoniter-scala:1.10.10 | |
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.10.10 | |
import caliban.* | |
import caliban.interop.tapir.* | |
import caliban.schema.Schema | |
import _root_.ox.* | |
import scala.concurrent.duration.* | |
import sttp.tapir.json.jsoniter.* | |
import sttp.tapir.server.netty.sync.{NettySyncServer, OxStreams} | |
import zio.Runtime | |
def computation1: Int = { sleep(2.seconds); 1 } | |
def computation2: String = { sleep(1.second); "2" } | |
case class Query( | |
result1: () => Int, | |
result2: () => String | |
) derives Schema.SemiAuto | |
val api: GraphQL[Any] = | |
graphQL( | |
RootResolver( | |
Query( | |
result1 = () => computation1, | |
result2 = () => computation2 | |
) | |
) | |
) | |
println(api.render) | |
val endpoints = | |
HttpInterpreter(api.interpreterUnsafe) | |
.serverEndpointsIdentity(OxStreams)(Runtime.default) | |
NettySyncServer().port(8080).addEndpoints(endpoints).startAndWait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment