-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Change `caliban-zio-http` to depend on caliban-quick * Add argument for ExecutionConfiguration
- Loading branch information
1 parent
b56673b
commit cc6a280
Showing
10 changed files
with
28 additions
and
261 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
48 changes: 17 additions & 31 deletions
48
adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala
This file contains 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
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
61
adapters/zio-http/src/test/scala/caliban/ZHttpAdapterSpec.scala
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
114 changes: 0 additions & 114 deletions
114
examples/src/main/scala/example/ziohttp/AuthExampleApp.scala
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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