Skip to content

Commit

Permalink
Update cats-effect to 3.1.0 and http4s to 1.0.0-M21
Browse files Browse the repository at this point in the history
  • Loading branch information
iRevive committed May 19, 2021
1 parent b6b8160 commit 52a74d3
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 175 deletions.
206 changes: 110 additions & 96 deletions adapters/http4s/src/main/scala/caliban/Http4sAdapter.scala

Large diffs are not rendered by default.

47 changes: 31 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ val scala3 = "3.0.0-RC3"
val allScala = Seq(scala212, scala213, scala3)

val akkaVersion = "2.6.14"
val catsEffectVersion = "2.5.1"
val catsEffectVersion = "3.1.0"
val circeVersion = "0.14.0-M6"
val http4sVersion = "0.21.23"
val http4sVersion = "1.0.0-M21"
val magnoliaVersion = "0.17.0"
val mercatorVersion = "0.2.1"
val playVersion = "2.8.8"
Expand All @@ -17,7 +17,7 @@ val silencerVersion = "1.7.3"
val sttpVersion = "3.3.2"
val tapirVersion = "0.17.18"
val zioVersion = "1.0.7"
val zioInteropCatsVersion = "2.4.1.0"
val zioInteropCatsVersion = "3.0.2.0"
val zioConfigVersion = "1.0.5"
val zqueryVersion = "0.2.8"
val zioJsonVersion = "0.1.4"
Expand Down Expand Up @@ -66,13 +66,13 @@ lazy val root = project
.aggregate(
macros,
core,
finch,
/*finch,*/
http4s,
akkaHttp,
play,
zioHttp,
catsInterop,
monixInterop,
/*monixInterop,*/
tapirInterop,
clientJVM,
clientJS,
Expand Down Expand Up @@ -187,15 +187,22 @@ lazy val catsInterop = project
.settings(name := "caliban-cats")
.settings(commonSettings)
.settings(
crossScalaVersions -= scala3,
libraryDependencies ++= Seq(
"dev.zio" %% "zio-interop-cats" % zioInteropCatsVersion,
"org.typelevel" %% "cats-effect" % catsEffectVersion
)
libraryDependencies ++= {
if (scalaVersion.value == scala3) {
Seq(
"org.typelevel" %% "cats-effect" % catsEffectVersion
)
} else {
Seq(
"org.typelevel" %% "cats-effect" % catsEffectVersion,
compilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.0").cross(CrossVersion.full))
)
}
}
)
.dependsOn(core)

lazy val monixInterop = project
/*lazy val monixInterop = project
.in(file("interop/monix"))
.settings(name := "caliban-monix")
.settings(commonSettings)
Expand All @@ -207,7 +214,7 @@ lazy val monixInterop = project
"io.monix" %% "monix" % "3.4.0"
)
)
.dependsOn(core)
.dependsOn(core)*/

lazy val tapirInterop = project
.in(file("interop/tapir"))
Expand Down Expand Up @@ -241,7 +248,7 @@ lazy val http4s = project
compilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.0").cross(CrossVersion.full))
)
)
.dependsOn(core)
.dependsOn(core, catsInterop)

lazy val zioHttp = project
.in(file("adapters/zio-http"))
Expand Down Expand Up @@ -273,7 +280,7 @@ lazy val akkaHttp = project
)
.dependsOn(core)

lazy val finch = project
/*lazy val finch = project
.in(file("adapters/finch"))
.settings(name := "caliban-finch")
.settings(commonSettings)
Expand All @@ -287,7 +294,7 @@ lazy val finch = project
"io.circe" %% "circe-parser" % circeVersion
)
)
.dependsOn(core)
.dependsOn(core)*/

lazy val play = project
.in(file("adapters/play"))
Expand All @@ -314,6 +321,7 @@ lazy val client = crossProject(JSPlatform, JVMPlatform)
.settings(name := "caliban-client")
.settings(commonSettings)
.settings(
crossScalaVersions -= scala3,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % circeVersion,
Expand Down Expand Up @@ -358,7 +366,14 @@ lazy val examples = project
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion
)
)
.dependsOn(akkaHttp, http4s, catsInterop, finch, play, monixInterop, tapirInterop, clientJVM, federation, zioHttp)
.dependsOn(
akkaHttp,
http4s,
catsInterop, /*finch,*/ play, /*monixInterop,*/ tapirInterop,
clientJVM,
federation,
zioHttp
)

lazy val benchmarks = project
.in(file("benchmarks"))
Expand Down
11 changes: 4 additions & 7 deletions examples/src/main/scala/example/federation/FederatedApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.http4s.server.Router
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.server.middleware.CORS
import zio._
import zio.blocking.Blocking
import zio.interop.catz._

import scala.concurrent.ExecutionContext
Expand All @@ -26,18 +25,17 @@ object FederatedApp extends CatsApp {
.memoize
.use(layer =>
for {
blocker <- ZIO.access[Blocking](_.get.blockingExecutor.asEC).map(Blocker.liftExecutionContext)
interpreter <- FederatedApi.Characters.api.interpreter.map(_.provideCustomLayer(layer))
_ <- BlazeServerBuilder[ExampleTask](ExecutionContext.global)
.bindHttp(8089, "localhost")
.withHttpApp(
Router[ExampleTask](
"/api/graphql" -> CORS(Http4sAdapter.makeHttpService(interpreter)),
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", blocker, None))
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", None))
).orNotFound
)
.resource
.toManaged
.toManagedZIO
.useForever
} yield ()
)
Expand All @@ -47,18 +45,17 @@ object FederatedApp extends CatsApp {
.memoize
.use(layer =>
for {
blocker <- ZIO.access[Blocking](_.get.blockingExecutor.asEC).map(Blocker.liftExecutionContext)
interpreter <- FederatedApi.Episodes.api.interpreter.map(_.provideCustomLayer(layer))
_ <- BlazeServerBuilder[ExampleTask](ExecutionContext.global)
.bindHttp(8088, "localhost")
.withHttpApp(
Router[ExampleTask](
"/api/graphql" -> CORS(Http4sAdapter.makeHttpService(interpreter)),
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", blocker, None))
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", None))
).orNotFound
)
.resource
.toManaged
.toManagedZIO
.useForever
} yield ()
)
Expand Down
2 changes: 2 additions & 0 deletions examples/src/main/scala/example/finch/ExampleApp.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package example.finch
/*
import example.ExampleData.sampleCharacters
import example.ExampleService.ExampleService
Expand Down Expand Up @@ -54,3 +55,4 @@ object ExampleApp extends App with Endpoint.Module[Task] {
Await.ready(server)
}
*/
9 changes: 4 additions & 5 deletions examples/src/main/scala/example/http4s/AuthExampleApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import org.http4s.dsl.Http4sDsl
import org.http4s.implicits._
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.server.{ Router, ServiceErrorHandler }
import org.http4s.util.CaseInsensitiveString
import org.typelevel.ci.CIString
import zio._
import zio.interop.catz._
import zio.interop.catz.implicits._

import scala.concurrent.ExecutionContext

Expand All @@ -34,8 +33,8 @@ object AuthExampleApp extends CatsApp {
def apply(route: HttpRoutes[AuthTask]): HttpRoutes[Task] =
Http4sAdapter.provideLayerFromRequest(
route,
_.headers.get(CaseInsensitiveString("token")) match {
case Some(value) => ZLayer.succeed(new Auth.Service { override def token: String = value.value })
_.headers.get(CIString("token")) match {
case Some(value) => ZLayer.succeed(new Auth.Service { override def token: String = value.head.value })
case None => ZLayer.fail(MissingToken())
}
)
Expand All @@ -62,7 +61,7 @@ object AuthExampleApp extends CatsApp {
.bindHttp(8088, "localhost")
.withHttpApp(Router[Task]("/api/graphql" -> route).orNotFound)
.resource
.toManaged
.toManagedZIO
.useForever
} yield ()).exitCode
}
7 changes: 2 additions & 5 deletions examples/src/main/scala/example/http4s/ExampleApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import example.{ ExampleApi, ExampleService }
import caliban.Http4sAdapter

import cats.data.Kleisli
import cats.effect.Blocker
import org.http4s.StaticFile
import org.http4s.implicits._
import org.http4s.server.Router
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.server.middleware.CORS
import zio._
import zio.blocking.Blocking
import zio.interop.catz._

import scala.concurrent.ExecutionContext
Expand All @@ -28,19 +26,18 @@ object ExampleApp extends App {
.runtime[ZEnv with ExampleService]
.flatMap(implicit runtime =>
for {
blocker <- ZIO.access[Blocking](_.get.blockingExecutor.asEC).map(Blocker.liftExecutionContext)
interpreter <- ExampleApi.api.interpreter
_ <- BlazeServerBuilder[ExampleTask](ExecutionContext.global)
.bindHttp(8088, "localhost")
.withHttpApp(
Router[ExampleTask](
"/api/graphql" -> CORS(Http4sAdapter.makeHttpService(interpreter)),
"/ws/graphql" -> CORS(Http4sAdapter.makeWebSocketService(interpreter)),
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", blocker, None))
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", None))
).orNotFound
)
.resource
.toManaged
.toManagedZIO
.useForever
} yield ()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import caliban.GraphQL.graphQL
import caliban.RootResolver

import cats.effect.{ ExitCode, IO, IOApp }
import cats.effect.std.Dispatcher
import zio.{ Runtime, ZEnv }

object ExampleCatsInterop extends IOApp {

import caliban.interop.cats.implicits._

implicit val runtime: Runtime[ZEnv] = Runtime.default
implicit val zioRuntime: Runtime[ZEnv] = Runtime.default

case class Number(value: Int)

Expand All @@ -20,7 +21,6 @@ object ExampleCatsInterop extends IOApp {
val randomNumber = IO(scala.util.Random.nextInt()).map(Number)

val queries = Queries(numbers, randomNumber)
val api = graphQL(RootResolver(queries))

val query = """
{
Expand All @@ -34,10 +34,14 @@ object ExampleCatsInterop extends IOApp {
}"""

override def run(args: List[String]): IO[ExitCode] =
for {
interpreter <- api.interpreterAsync[IO]
_ <- interpreter.checkAsync[IO](query)
result <- interpreter.executeAsync[IO](query)
_ <- IO(println(result.data))
} yield ExitCode.Success
Dispatcher[IO].use { implicit dispatcher => // required for a derivation of the schema
val api = graphQL(RootResolver(queries))

for {
interpreter <- api.interpreterAsync[IO]
_ <- interpreter.checkAsync[IO](query)
result <- interpreter.executeAsync[IO](query)
_ <- IO(println(result.data))
} yield ExitCode.Success
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package example.interop.monix
/*
import caliban.GraphQL.graphQL
import caliban.ResponseValue.{ ObjectValue, StreamValue }
Expand Down Expand Up @@ -61,3 +62,4 @@ object ExampleMonixInterop extends TaskApp {
}
} yield ExitCode.Success
}
*/
8 changes: 2 additions & 6 deletions examples/src/main/scala/example/tapir/ExampleApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import caliban.interop.tapir._
import caliban.{ GraphQL, Http4sAdapter }

import cats.data.Kleisli
import cats.effect.Blocker
import org.http4s.StaticFile
import org.http4s.implicits._
import org.http4s.server.Router
import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.server.middleware.CORS
import sttp.tapir.server.ServerEndpoint
import zio._
import zio.blocking.Blocking
import zio.interop.catz._
import zio.interop.catz.implicits._

import scala.concurrent.ExecutionContext

Expand All @@ -43,18 +40,17 @@ object ExampleApp extends CatsApp {

override def run(args: List[String]): ZIO[ZEnv, Nothing, ExitCode] =
(for {
blocker <- ZIO.access[Blocking](_.get.blockingExecutor.asEC).map(Blocker.liftExecutionContext)
interpreter <- graphql.interpreter
_ <- BlazeServerBuilder[Task](ExecutionContext.global)
.bindHttp(8088, "localhost")
.withHttpApp(
Router[Task](
"/api/graphql" -> CORS(Http4sAdapter.makeHttpService(interpreter)),
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", blocker, None))
"/graphiql" -> Kleisli.liftF(StaticFile.fromResource("/graphiql.html", None))
).orNotFound
)
.resource
.toManaged
.toManagedZIO
.useForever
} yield ()).exitCode
}
Loading

0 comments on commit 52a74d3

Please sign in to comment.