Skip to content

Instantly share code, notes, and snippets.

@tkawachi
Last active June 9, 2022 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkawachi/d1d8d219cdd8114f4a8964e4ff74260a to your computer and use it in GitHub Desktop.
Save tkawachi/d1d8d219cdd8114f4a8964e4ff74260a to your computer and use it in GitHub Desktop.
Can't get operationName
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.8"
lazy val root = (project in file("."))
.settings(
name := "opname",
libraryDependencies ++= Seq("com.github.ghostdogpr" %% "caliban" % "1.4.1")
)
package opname
import caliban.GraphQL.graphQL
import caliban.{CalibanError, GraphQLRequest, GraphQLResponse, RootResolver}
import caliban.wrappers.Wrapper.OverallWrapper
import zio.{UIO, ZIO}
case class Query(hello: String)
object Main {
val wrapper = new OverallWrapper[Any] {
override def wrap[R1 <: Any](
f: GraphQLRequest => ZIO[R1, Nothing, GraphQLResponse[CalibanError]]
): GraphQLRequest => ZIO[R1, Nothing, GraphQLResponse[CalibanError]] =
request =>
for {
// operationName always seems to be None
_ <- UIO(println(s"operationName: ${request.operationName}"))
result <- f(request)
} yield result
}
def main(args: Array[String]): Unit = {
val query = Query("World!")
val api = graphQL(RootResolver(query)) @@ wrapper
val io = for {
interpreter <- api.interpreter
result <- interpreter.execute("query MyOp {hello}")
} yield println(result)
zio.Runtime.default.unsafeRun(io)
}
}
operationName: None
GraphQLResponse({"hello":"World!"},List(),None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment