ZIO 2.0.0 zio-http Scala 3.1.2 Caliban error
jowparks opened this issue · comments
I wrote a simple App using the amalgamation of the docs here, on ZIO website, and on zio-http docs. I am getting a compiler error that seems to be an issue with ZIO 1.x -> 2.x conversion.
.../src/main/scala/App.scala:45:9
zio.clock.package.Clock is not defined in inferred type zio.ZIO[zio.clock.package.Clock, Throwable, Unit]
val serverIO = for {
In ZIO 2, the built in layers should be automatically provided. So I am surprised by this error. Not sure if this is an issue with zio-http or caliban.
The simple App:
import caliban.GraphQL.graphQL
import caliban.schema.Annotations.GQLDescription
import caliban.{RootResolver, ZHttpAdapter}
import zio._
import zio.stream.*
import zhttp.http.*
import zhttp.service.Server
sealed trait Role
object Role {
case object SoftwareDeveloper extends Role
case object SiteReliabilityEngineer extends Role
case object DevOps extends Role
}
case class Employee(
name: String,
role: Role
)
case class EmployeesArgs(role: Role)
case class EmployeeArgs(name: String)
case class Queries(
@GQLDescription("Return all employees with specific role")
employees: EmployeesArgs => List[Employee],
@GQLDescription("Find an employee by its name")
employee: EmployeeArgs => Option[Employee]
)
object Myapp extends ZIOAppDefault {
private val graphiql = Http.fromStream(ZStream.fromResource("graphiql.html"))
val employees: List[Employee] = List(
Employee("Alex", Role.DevOps),
Employee("Maria", Role.SoftwareDeveloper),
Employee("James", Role.SiteReliabilityEngineer),
Employee("Peter", Role.SoftwareDeveloper),
Employee("Julia", Role.SiteReliabilityEngineer),
Employee("Roberta", Role.DevOps)
)
def run = {
val serverIO = for {
interpreter <- graphQL(
RootResolver(
Queries(
args => employees.filter(e => args.role == e.role),
args => employees.find(e => e.name == args.name)
)
)
).interpreter
_ <- Server
.start(
8088,
Http.collectHttp[Request] {
case _ -> !! / "api" / "graphql" => ZHttpAdapter.makeHttpService(interpreter)
case _ -> !! / "ws" / "graphql" => ZHttpAdapter.makeWebSocketService(interpreter)
case _ -> !! / "graphiql" => graphiql
}
)
.forever
} yield ()
serverIO.exitCode
}
}
I tried using a version of the example for the zio-http
server with these dependencies:
ThisBuild / version := "0.1.0"
ThisBuild / scalaVersion := "3.1.2"
val zioVersion = "2.0.0"
val circeVersion = "0.15.0-M1"
val doobieVersion = "1.0.0-RC2"
val calibanVersion = "1.4.1"
val zhttpVersion = "2.0.0-RC9"
val zioConfigVersion = "3.0.0-RC9"
val zioCatsInteropVersion = "3.2.9.1"
val zioTestFramework = new TestFramework("zio.test.sbt.ZTestFramework")
lazy val root = (project in file("."))
.settings(
name := "rdphttp2",
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-cli" % "0.2.6",
"dev.zio" %% "zio-optics" % "0.2.0",
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
"dev.zio" %% "zio-interop-cats" % zioCatsInteropVersion,
"com.github.ghostdogpr" %% "caliban" % calibanVersion,
"com.github.ghostdogpr" %% "caliban-zio-http" % calibanVersion,
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.d11" %% "zhttp" % zhttpVersion,
"io.d11" %% "zhttp-test" % zhttpVersion,
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-postgres" % doobieVersion,
"org.tpolecat" %% "doobie-postgres-circe" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"dev.zio" %% "zio-config" % zioConfigVersion,
"dev.zio" %% "zio-config-typesafe" % zioConfigVersion,
"dev.zio" %% "zio-config-magnolia" % zioConfigVersion,
),
testFrameworks += zioTestFramework
)
scalacOptions ++= Seq("-deprecation", "-feature")
Caliban 1.4.1 depends on ZIO 1 and you are using ZIO 2. They are not compatible.
You have the same problem with multiple dependencies. Everything that depends on ZIO must be aligned.
At the moment, Caliban (as well as zio-http) is not released for ZIO 2.0 final because some dependencies are still missing. Your choices are using ZIO 1.0 (and update all your dependencies accordingly) or ZIO 2.0-RC6 (with caliban snapshot version 2.0.0-RC2+65-0d8061df-SNAPSHOT
, also update your dependencies accordingly).
Ahh thanks a ton @ghostdogpr , makes sense!