Last active
June 9, 2022 01:25
-
-
Save tkawachi/d1d8d219cdd8114f4a8964e4ff74260a to your computer and use it in GitHub Desktop.
Can't get operationName
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
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") | |
) |
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
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) | |
} | |
} |
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
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