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

Change caliban-zio-http to depend on caliban-quick #2287

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ jobs:
- checkout
- restore_cache:
key: sbtcache
- run: sbt ++2.13 http4s/mimaReportBinaryIssues akkaHttp/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues quickAdapter/mimaReportBinaryIssues zioHttp/mimaReportBinaryIssues play/mimaReportBinaryIssues # tools/mimaReportBinaryIssues
- run: sbt ++3.3 catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues http4s/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues quickAdapter/mimaReportBinaryIssues zioHttp/mimaReportBinaryIssues play/mimaReportBinaryIssues # tools/mimaReportBinaryIssues
- run: sbt ++2.13 http4s/mimaReportBinaryIssues akkaHttp/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues quickAdapter/mimaReportBinaryIssues play/mimaReportBinaryIssues # tools/mimaReportBinaryIssues
- run: sbt ++3.3 catsInterop/mimaReportBinaryIssues monixInterop/mimaReportBinaryIssues clientJVM/mimaReportBinaryIssues clientJS/mimaReportBinaryIssues clientLaminextJS/mimaReportBinaryIssues http4s/mimaReportBinaryIssues federation/mimaReportBinaryIssues reporting/mimaReportBinaryIssues tracing/mimaReportBinaryIssues core/mimaReportBinaryIssues tapirInterop/mimaReportBinaryIssues pekkoHttp/mimaReportBinaryIssues quickAdapter/mimaReportBinaryIssues play/mimaReportBinaryIssues # tools/mimaReportBinaryIssues
- save_cache:
key: sbtcache
paths:
Expand Down
2 changes: 1 addition & 1 deletion adapters/quick/src/main/scala/caliban/QuickAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class QuickAdapter[R] private (requestHandler: QuickRequestHandler[R]) {
Handler.fromFunctionZIO[Request](requestHandler.handleHttpRequest)

/**
* Converts this adapter to an `Routes` serving the GraphQL API at the specified path.
* Converts this adapter to a `Routes` serving the GraphQL API at the specified path.
*
* @param apiPath The path where the GraphQL API will be served.
* @param graphiqlPath The path where the GraphiQL UI will be served. If None, GraphiQL will not be served.
Expand Down
6 changes: 3 additions & 3 deletions adapters/quick/src/test/scala/caliban/QuickAdapterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import caliban.uploads.Uploads
import sttp.client3.UriContext
import zio._
import zio.http._
import zio.test.{ Live, TestAspect, ZIOSpecDefault }
import zio.test.{ Live, ZIOSpecDefault }

import scala.language.postfixOps

Expand All @@ -24,10 +24,10 @@ object QuickAdapterSpec extends ZIOSpecDefault {

private val apiLayer = envLayer >>> ZLayer.fromZIO {
for {
app <- TestApi.api
_ <- TestApi.api
.routes("/api/graphql", uploadPath = Some("/upload/graphql"), webSocketPath = Some("/ws/graphql"))
.map(_ @@ auth)
_ <- Server.serve(app).forkScoped
.flatMap(_.serve[TestService & Uploads].forkScoped)
_ <- Live.live(Clock.sleep(3 seconds))
service <- ZIO.service[TestService]
} yield service
Expand Down
48 changes: 17 additions & 31 deletions adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
package caliban

import caliban.interop.tapir.{ HttpInterpreter, WebSocketInterpreter }
import caliban.ws.Protocol
import sttp.capabilities.zio.ZioStreams
import sttp.model.HeaderNames
import sttp.tapir.server.ziohttp.{ ZioHttpInterpreter, ZioHttpServerOptions }
import zio.http._
import caliban.Configurator.ExecutionConfiguration
import caliban.ws.WebSocketHooks
import zio.Duration
import zio.http.{ WebSocketConfig => ZWebSocketConfig, _ }

@deprecated(
"The `caliban-zio-http` package is deprecated and scheduled to be removed in a future release. To use Caliban with zio-http, use the `caliban-quick` module instead",
"2.6.0"
)
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.subProtocol(Some(subProtocols))
}

def makeHttpService[R, E](interpreter: HttpInterpreter[R, E])(implicit
serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]
def makeHttpService[R, E](
interpreter: GraphQLInterpreter[R, E],
config: ExecutionConfiguration = ExecutionConfiguration()
): RequestHandler[R, Nothing] =
ZioHttpInterpreter(serverOptions)
.toHttp(interpreter.serverEndpoints[R, ZioStreams](ZioStreams))
.toHandler
QuickAdapter(interpreter).configure(config).handlers.api

def makeWebSocketService[R, E](interpreter: WebSocketInterpreter[R, E])(implicit
serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]
): RequestHandler[R, Nothing] =
ZioHttpInterpreter(patchWsServerOptions(serverOptions))
.toHttp(interpreter.serverEndpoint[R])
.toHandler
def makeWebSocketService[R, E](
interpreter: GraphQLInterpreter[R, E],
keepAliveTime: Option[Duration] = None,
webSocketHooks: WebSocketHooks[R, E] = WebSocketHooks.empty,
zHttpConfig: ZWebSocketConfig = ZWebSocketConfig.default
): RequestHandler[R, Nothing] = {
val config = quick.WebSocketConfig(keepAliveTime, webSocketHooks, zHttpConfig)
QuickAdapter(interpreter).configureWebSocket(config).handlers.webSocket
}

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))
}
}
}
61 changes: 0 additions & 61 deletions adapters/zio-http/src/test/scala/caliban/ZHttpAdapterSpec.scala

This file was deleted.

10 changes: 1 addition & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,7 @@ lazy val zioHttp = project
.settings(commonSettings)
.settings(enableMimaSettingsJVM)
.disablePlugins(AssemblyPlugin)
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio-http" % zioHttpVersion,
"com.softwaremill.sttp.tapir" %% "tapir-zio-http-server" % tapirVersion,
"dev.zio" %% "zio-json" % zioJsonVersion % Test,
"com.softwaremill.sttp.tapir" %% "tapir-json-zio" % tapirVersion % Test
)
)
.dependsOn(core, tapirInterop % "compile->compile;test->test")
.dependsOn(core, quickAdapter)

lazy val quickAdapter = project
.in(file("adapters/quick"))
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/caliban/ws/WebSocketHooks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ trait WebSocketHooks[-R, +E] { self =>
}

object WebSocketHooks {
def empty[R, E]: WebSocketHooks[R, E] = new WebSocketHooks[R, E] {}
def empty[R, E]: WebSocketHooks[R, E] = Empty

private case object Empty extends WebSocketHooks[Any, Nothing]

/**
* Specifies a callback that will be run before an incoming subscription
Expand Down
114 changes: 0 additions & 114 deletions examples/src/main/scala/example/ziohttp/AuthExampleApp.scala

This file was deleted.

38 changes: 0 additions & 38 deletions examples/src/main/scala/example/ziohttp/ExampleApp.scala

This file was deleted.

2 changes: 1 addition & 1 deletion vuepress/docs/docs/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ for {
Method.POST / "upload" / "graphql" -> handlers.upload
// Add more routes, apply middleware, etc.
)
_ <- Server.serve(app).provide(Server.defaultWithPort(8080))
_ <- app.serve[Any].provide(Server.defaultWithPort(8080))
} yield ()
```

Expand Down
Loading