-
-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathZHttpAdapter.scala
29 lines (24 loc) · 1.07 KB
/
ZHttpAdapter.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package caliban
import caliban.interop.tapir.ws.Protocol
import caliban.interop.tapir.{ HttpInterpreter, WebSocketInterpreter }
import sttp.capabilities.zio.ZioStreams
import sttp.tapir.server.ziohttp.{ ZioHttpInterpreter, ZioHttpServerOptions }
import zio.http._
object ZHttpAdapter {
val defaultWebSocketConfig: WebSocketConfig = {
val subProtocols = List(Protocol.Legacy.name, Protocol.GraphQLWS.name).mkString(",")
WebSocketConfig.default.withSubProtocol(Some(subProtocols))
}
def makeHttpService[R, E](interpreter: HttpInterpreter[R, E])(implicit
serverOptions: ZioHttpServerOptions[R] = ZioHttpServerOptions.default[R]
): App[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)
.toHttp(interpreter.serverEndpoint[R])
.withDefaultErrorResponse
}