Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update zio-http to RC4 & Play to 3.0.0 #1968

Merged
merged 18 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- checkout
- restore_cache:
key: sbtcache
- run: sbt ++2.12.18 core/test http4s/test akkaHttp/test pekkoHttp/test play/test zioHttp/test examples/compile catsInterop/test tools/test codegenSbt/test clientJVM/test monixInterop/compile tapirInterop/test federation/test reporting/test tracing/test
- run: sbt ++2.12.18 core/test http4s/test akkaHttp/test pekkoHttp/test zioHttp/test examples/compile catsInterop/test tools/test codegenSbt/test clientJVM/test monixInterop/compile tapirInterop/test federation/test reporting/test tracing/test
- save_cache:
key: sbtcache
paths:
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
- checkout
- restore_cache:
key: sbtcache
- run: sbt ++3.3.1 core/test catsInterop/test benchmarks/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/test tapirInterop/test pekkoHttp/test http4s/test federation/test tools/test reporting/test tracing/test
- run: sbt ++3.3.1 core/test catsInterop/test benchmarks/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/test tapirInterop/test pekkoHttp/test http4s/test play/test federation/test tools/test reporting/test tracing/test
- save_cache:
key: sbtcache
paths:
Expand All @@ -113,7 +113,7 @@ jobs:
- checkout
- restore_cache:
key: sbtcache
- run: sbt ++3.3.1 core/test catsInterop/test benchmarks/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/test tapirInterop/test pekkoHttp/test http4s/test federation/test tools/test reporting/test tracing/test
- run: sbt ++3.3.1 core/test catsInterop/test benchmarks/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/test tapirInterop/test pekkoHttp/test http4s/test play/test federation/test tools/test reporting/test tracing/test
- save_cache:
key: sbtcache
paths:
Expand Down Expand Up @@ -177,8 +177,8 @@ jobs:
- checkout
- restore_cache:
key: sbtcache
- run: sbt ++2.13.12 http4s/mimaReportBinaryIssues akkaHttp/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues play/mimaReportBinaryIssues zioHttp/mimaReportBinaryIssues catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues tools/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues
- run: sbt ++3.3.1 catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues zioHttp/mimaReportBinaryIssues http4s/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues tools/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues
- run: sbt ++2.13.12 http4s/mimaReportBinaryIssues akkaHttp/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues tools/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues # zioHttp/mimaReportBinaryIssues play/mimaReportBinaryIssues
- run: sbt ++3.3.1 catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues http4s/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues tools/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues # zioHttp/mimaReportBinaryIssues play/mimaReportBinaryIssues
- save_cache:
key: sbtcache
paths:
Expand Down
34 changes: 17 additions & 17 deletions adapters/play/src/main/scala/caliban/PlayAdapter.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package caliban

import akka.stream.scaladsl.{ Flow, Sink, Source }
import akka.stream.{ Materializer, OverflowStrategy }
import akka.util.ByteString
import caliban.PlayAdapter.convertHttpStreamingEndpoint
import caliban.interop.tapir.TapirAdapter._
import caliban.interop.tapir.{ HttpInterpreter, HttpUploadInterpreter, StreamConstructor, WebSocketInterpreter }
import org.apache.pekko.stream.scaladsl.{ Flow, Sink, Source }
import org.apache.pekko.stream.{ Materializer, OverflowStrategy }
import org.apache.pekko.util.ByteString
import play.api.routing.Router.Routes
import sttp.capabilities.{ akka, WebSockets }
import sttp.capabilities.akka.AkkaStreams
import sttp.capabilities.akka.AkkaStreams.Pipe
import sttp.model.{ MediaType, StatusCode }
import sttp.capabilities.WebSockets
import sttp.capabilities.pekko.PekkoStreams
import sttp.capabilities.pekko.PekkoStreams.Pipe
import sttp.model.StatusCode
import sttp.tapir.Codec.JsonCodec
import sttp.tapir.PublicEndpoint
import sttp.tapir.model.ServerRequest
Expand All @@ -30,7 +30,7 @@ class PlayAdapter private (private val options: Option[PlayServerOptions]) {
)(implicit runtime: Runtime[R], materializer: Materializer): Routes =
playInterpreter.toRoutes(
interpreter
.serverEndpoints[R, AkkaStreams](AkkaStreams)
.serverEndpoints[R, PekkoStreams](PekkoStreams)
.map(convertHttpStreamingEndpoint[R, (GraphQLRequest, ServerRequest)])
)

Expand All @@ -40,7 +40,7 @@ class PlayAdapter private (private val options: Option[PlayServerOptions]) {
requestCodec: JsonCodec[GraphQLRequest],
mapCodec: JsonCodec[Map[String, Seq[String]]]
): Routes =
playInterpreter.toRoutes(convertHttpStreamingEndpoint(interpreter.serverEndpoint[R, AkkaStreams](AkkaStreams)))
playInterpreter.toRoutes(convertHttpStreamingEndpoint(interpreter.serverEndpoint[R, PekkoStreams](PekkoStreams)))

def makeWebSocketService[R, E](
interpreter: WebSocketInterpreter[R, E]
Expand All @@ -66,7 +66,7 @@ class PlayAdapter private (private val options: Option[PlayServerOptions]) {
private implicit def streamConstructor(implicit
runtime: Runtime[Any],
mat: Materializer
): StreamConstructor[AkkaStreams.BinaryStream] =
): StreamConstructor[PekkoStreams.BinaryStream] =
new StreamConstructor[Source[ByteString, Any]] {
override def apply(stream: ZStream[Any, Throwable, Byte]): Source[ByteString, Any] =
Unsafe.unsafe(implicit u =>
Expand Down Expand Up @@ -111,18 +111,18 @@ object PlayAdapter extends PlayAdapter(None) {
Unit,
Input,
TapirResponse,
CalibanResponse[AkkaStreams.BinaryStream],
AkkaStreams,
CalibanResponse[PekkoStreams.BinaryStream],
PekkoStreams,
RIO[R, *]
]
)(implicit runtime: Runtime[R], mat: Materializer): ServerEndpoint[AkkaStreams, Future] =
)(implicit runtime: Runtime[R], mat: Materializer): ServerEndpoint[PekkoStreams, Future] =
ServerEndpoint[
Unit,
Unit,
Input,
TapirResponse,
CalibanResponse[akka.AkkaStreams.BinaryStream],
AkkaStreams,
CalibanResponse[PekkoStreams.BinaryStream],
PekkoStreams,
Future
](
endpoint.endpoint,
Expand Down Expand Up @@ -151,14 +151,14 @@ object PlayAdapter extends PlayAdapter(None) {
)(implicit
runtime: Runtime[R],
materializer: Materializer
): ServerEndpoint[AkkaStreams with WebSockets, Future] =
): ServerEndpoint[PekkoStreams with WebSockets, Future] =
ServerEndpoint[
Unit,
Unit,
(ServerRequest, String),
StatusCode,
(String, AkkaPipe),
AkkaStreams with WebSockets,
PekkoStreams with WebSockets,
Future
](
endpoint.endpoint
Expand Down
10 changes: 5 additions & 5 deletions adapters/play/src/test/scala/caliban/PlayAdapterSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package caliban

import akka.actor.ActorSystem
import akka.stream.Materializer
import caliban.interop.tapir.TestData.sampleCharacters
import caliban.interop.tapir.{
FakeAuthorizationInterceptor,
Expand All @@ -13,18 +11,20 @@ import caliban.interop.tapir.{
WebSocketInterpreter
}
import caliban.uploads.Uploads
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.Materializer
import play.api.Mode
import play.api.routing._
import play.api.routing.sird._
import play.core.server.{ AkkaHttpServer, ServerConfig }
import play.core.server.{ PekkoHttpServer, ServerConfig }
import sttp.client3.UriContext
import zio._
import zio.test.{ Live, ZIOSpecDefault }

import scala.language.postfixOps

object PlayAdapterSpec extends ZIOSpecDefault {
import sttp.tapir.json.circe._
import sttp.tapir.json.play._

private val envLayer = TestService.make(sampleCharacters) ++ Uploads.empty

Expand All @@ -51,7 +51,7 @@ object PlayAdapterSpec extends ZIOSpecDefault {
}
_ <- ZIO
.attempt(
AkkaHttpServer.fromRouterWithComponents(
PekkoHttpServer.fromRouterWithComponents(
ServerConfig(
mode = Mode.Dev,
port = Some(8088),
Expand Down
21 changes: 15 additions & 6 deletions adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@ package caliban
import caliban.interop.tapir.ws.Protocol
import caliban.interop.tapir.{ HttpInterpreter, WebSocketInterpreter }
import sttp.capabilities.zio.ZioStreams
import sttp.model.HeaderNames
import sttp.tapir.server.ziohttp.{ ZioHttpInterpreter, ZioHttpServerOptions }
import zio.http._

object ZHttpAdapter {

@deprecated("Defining subprotocols in the server config is no longer required")
val defaultWebSocketConfig: WebSocketConfig = {
val subProtocols = List(Protocol.Legacy.name, Protocol.GraphQLWS.name).mkString(",")
WebSocketConfig.default.withSubProtocol(Some(subProtocols))
WebSocketConfig.default.subProtocol(Some(subProtocols))
}

def makeHttpService[R, E](interpreter: HttpInterpreter[R, E])(implicit
serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]
): App[R] =
): HttpApp[R] =
ZioHttpInterpreter(serverOptions)
.toHttp(interpreter.serverEndpoints[R, ZioStreams](ZioStreams))
.withDefaultErrorResponse

def makeWebSocketService[R, E](interpreter: WebSocketInterpreter[R, E])(implicit
serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]
): App[R] =
ZioHttpInterpreter(serverOptions)
): HttpApp[R] =
ZioHttpInterpreter(patchWsServerOptions(serverOptions))
.toHttp(interpreter.serverEndpoint[R])
.withDefaultErrorResponse

private def patchWsServerOptions[R](serverOptions: ZioHttpServerOptions[R]) =
serverOptions.withCustomWebSocketConfig { req =>
val protocol = req.header(HeaderNames.SecWebSocketProtocol).fold(Protocol.Legacy: Protocol)(Protocol.fromName)
serverOptions.customWebSocketConfig(req) match {
case Some(existing) => existing.subProtocol(Some(protocol.name))
case _ => WebSocketConfig.default.subProtocol(Some(protocol.name))
}
}
kyri-petrou marked this conversation as resolved.
Show resolved Hide resolved
}
21 changes: 9 additions & 12 deletions adapters/zio-http/src/test/scala/caliban/ZHttpAdapterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ object ZHttpAdapterSpec extends ZIOSpecDefault {
_ <-
Server
.serve(
Http
.collectHttp[Request] {
case _ -> Root / "api" / "graphql" =>
ZHttpAdapter.makeHttpService(
Routes(
Method.ANY / "api" / "graphql" ->
ZHttpAdapter
.makeHttpService(
HttpInterpreter(interpreter).intercept(FakeAuthorizationInterceptor.bearer[TestService & Uploads])
)
case _ -> Root / "ws" / "graphql" =>
ZHttpAdapter.makeWebSocketService(WebSocketInterpreter(interpreter))
}
.toHandler,
Method.ANY / "ws" / "graphql" ->
ZHttpAdapter.makeWebSocketService(WebSocketInterpreter(interpreter)).toHandler
).toHttpApp
)
.forkScoped
_ <- Live.live(Clock.sleep(3 seconds))
Expand All @@ -53,11 +54,7 @@ object ZHttpAdapterSpec extends ZIOSpecDefault {
suite.provideShared(
apiLayer,
Scope.default,
Server.defaultWith(
_.withWebSocketConfig(ZHttpAdapter.defaultWebSocketConfig)
.port(8089)
.responseCompression()
)
Server.defaultWith(_.port(8089).responseCompression())
)
}
}
68 changes: 35 additions & 33 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ val laminextVersion = "0.16.2"
val magnoliaScala2Version = "1.1.6"
val magnoliaScala3Version = "1.3.4"
val pekkoVersion = "1.0.1"
val playVersion = "2.8.20"
val playJsonVersion = "2.10.2"
val playVersion = "3.0.0"
val playJsonVersion = "3.0.0"
val scalafmtVersion = "3.7.14"
val sttpVersion = "3.9.0"
val tapirVersion = "1.8.2"
val tapirVersion = "1.8.5"
val zioVersion = "2.0.18"
val zioInteropCats2Version = "22.0.0.0"
val zioInteropCats3Version = "23.0.0.8"
val zioInteropReactiveVersion = "2.0.2"
val zioConfigVersion = "3.0.7"
val zqueryVersion = "0.5.1"
val zioJsonVersion = "0.6.2"
val zioHttpVersion = "3.0.0-RC2"
val zioHttpVersion = "3.0.0-RC3"
val zioOpenTelemetryVersion = "3.0.0-RC15"
val zioPreludeVersion = "1.0.0-RC21"

Expand Down Expand Up @@ -150,7 +150,7 @@ lazy val core = project
"io.circe" %% "circe-parser" % circeVersion % Test,
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-core" % jsoniterVersion % Optional,
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % jsoniterVersion % Provided,
"com.typesafe.play" %% "play-json" % playJsonVersion % Optional
"org.playframework" %% "play-json" % playJsonVersion % Optional
)
)
.dependsOn(macros)
Expand Down Expand Up @@ -393,20 +393,22 @@ lazy val play = project
.settings(commonSettings)
.settings(enableMimaSettingsJVM)
.settings(
skip := (scalaVersion.value == scala3),
ideSkipProject := (scalaVersion.value == scala3),
crossScalaVersions -= scala3,
skip := (scalaVersion.value == scala212),
ideSkipProject := (scalaVersion.value == scala212),
crossScalaVersions -= scala212,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
libraryDependencies ++= {
if (scalaVersion.value == scala3) Seq()
else Seq(compilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.2").cross(CrossVersion.full)))
},
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play" % playVersion,
"com.softwaremill.sttp.tapir" %% "tapir-play-server" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion % Test,
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
"com.typesafe.play" %% "play-akka-http-server" % playVersion % Test,
"io.circe" %% "circe-generic" % circeVersion % Test,
"com.softwaremill.sttp.client3" %% "circe" % sttpVersion % Test,
compilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.2").cross(CrossVersion.full))
"org.playframework" %% "play" % playVersion,
"com.softwaremill.sttp.tapir" %% "tapir-play-server" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-play" % tapirVersion % Test,
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
"org.playframework" %% "play-pekko-http-server" % playVersion % Test,
"org.playframework" %% "play-json" % playJsonVersion % Test
)
)
.dependsOn(core, tapirInterop % "compile->compile;test->test")
Expand Down Expand Up @@ -486,24 +488,24 @@ lazy val examples = project
run / connectInput := true
)
.settings(
skip := (scalaVersion.value == scala3),
ideSkipProject := (scalaVersion.value == scala3),
crossScalaVersions -= scala3,
skip := (scalaVersion.value != scala213),
ideSkipProject := (scalaVersion.value != scala213),
crossScalaVersions := Seq(scala213),
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-java8-compat" % "always",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-mtl" % catsMtlVersion,
"org.http4s" %% "http4s-ember-server" % http4sVersion,
"org.http4s" %% "http4s-dsl" % http4sVersion,
"com.softwaremill.sttp.client3" %% "zio" % sttpVersion,
"io.circe" %% "circe-generic" % circeVersion,
"dev.zio" %% "zio-http" % zioHttpVersion,
"com.typesafe.play" %% "play-akka-http-server" % playVersion,
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-play" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % tapirVersion,
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % jsoniterVersion % Provided
"org.typelevel" %% "cats-mtl" % catsMtlVersion,
"org.http4s" %% "http4s-ember-server" % http4sVersion,
"org.http4s" %% "http4s-dsl" % http4sVersion,
"com.softwaremill.sttp.client3" %% "zio" % sttpVersion,
"io.circe" %% "circe-generic" % circeVersion,
"dev.zio" %% "zio-http" % zioHttpVersion,
"org.playframework" %% "play-pekko-http-server" % playVersion,
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-json-play" % tapirVersion,
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % tapirVersion,
"com.github.plokhotnyuk.jsoniter-scala" %% "jsoniter-scala-macros" % jsoniterVersion % Provided
)
)
.dependsOn(
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libraryDependencies ++= Seq(
"org.http4s" %% "http4s-dsl" % "0.23.23",
"com.softwaremill.sttp.client3" %% "zio" % "3.9.0",
"io.circe" %% "circe-generic" % "0.14.6",
"org.playframework" %% "play-akka-http-server" % "2.8.14",
"org.playframework" %% "play-pekko-http-server" % "3.0.0",
"com.typesafe.akka" %% "akka-actor-typed" % "2.6.18",
"com.softwaremill.sttp.tapir" %% "tapir-jsoniter-scala" % "1.8.2"
)
Expand Down
Loading