@@ -19,21 +19,24 @@ sealed trait HttpInterpreter[-R, E] { self =>
19
19
serverRequest : ServerRequest
20
20
)(implicit streamConstructor : StreamConstructor [BS ]): ZIO [R , TapirResponse , CalibanResponse [BS ]]
21
21
22
- def serverEndpoints [R1 <: R , S ](stream : Streams [S ])(implicit
23
- streamConstructor : StreamConstructor [stream .BinaryStream ]
24
- ): List [CalibanEndpoint [R1 , stream .BinaryStream , S ]] = {
22
+ def serverEndpoints [R1 <: R , S ](streams : Streams [S ])(implicit
23
+ streamConstructor : StreamConstructor [streams .BinaryStream ]
24
+ ): List [CalibanEndpoint [R1 , streams .BinaryStream , S ]] = {
25
25
def logic (
26
26
request : (GraphQLRequest , ServerRequest )
27
- ): RIO [R1 , Either [TapirResponse , CalibanResponse [stream .BinaryStream ]]] = {
27
+ ): RIO [R1 , Either [TapirResponse , CalibanResponse [streams .BinaryStream ]]] = {
28
28
val (graphQLRequest, serverRequest) = request
29
29
executeRequest(graphQLRequest, serverRequest).either
30
30
}
31
- endpoints[S ](stream ).map(_.serverLogic(logic(_)))
31
+ endpoints[S ](streams ).map(_.serverLogic(logic(_)))
32
32
}
33
33
34
34
def intercept [R1 ](interceptor : Interceptor [R1 , R ]): HttpInterpreter [R1 , E ] =
35
35
HttpInterpreter .Intercepted (self, interceptor)
36
36
37
+ def prependPath (path : List [String ]): HttpInterpreter [R , E ] =
38
+ HttpInterpreter .Prepended (self, path)
39
+
37
40
def configure [R1 ](configurator : Configurator [R1 ]): HttpInterpreter [R & R1 , E ] =
38
41
intercept[R & R1 ](ZLayer .scopedEnvironment[R & R1 & ServerRequest ](configurator *> ZIO .environment[R ]))
39
42
}
@@ -63,6 +66,33 @@ object HttpInterpreter {
63
66
}
64
67
}
65
68
69
+ private case class Prepended [R , E ](
70
+ interpreter : HttpInterpreter [R , E ],
71
+ path : List [String ]
72
+ ) extends HttpInterpreter [R , E ] {
73
+ override def endpoints [S ](
74
+ streams : Streams [S ]
75
+ ): List [
76
+ PublicEndpoint [(GraphQLRequest , ServerRequest ), TapirResponse , CalibanResponse [streams.BinaryStream ], S ]
77
+ ] = {
78
+ val endpoints = interpreter.endpoints(streams)
79
+ if (path.nonEmpty) {
80
+ val p : List [EndpointInput [Unit ]] = path.map(stringToPath)
81
+ val fixedPath : EndpointInput [Unit ] = p.tail.foldLeft(p.head)(_ / _)
82
+
83
+ endpoints.map(_.prependIn(fixedPath))
84
+ } else {
85
+ endpoints
86
+ }
87
+ }
88
+
89
+ def executeRequest [BS ](
90
+ graphQLRequest : GraphQLRequest ,
91
+ serverRequest : ServerRequest
92
+ )(implicit streamConstructor : StreamConstructor [BS ]): ZIO [R , TapirResponse , CalibanResponse [BS ]] =
93
+ interpreter.executeRequest(graphQLRequest, serverRequest)
94
+ }
95
+
66
96
private case class Intercepted [R1 , R , E ](
67
97
interpreter : HttpInterpreter [R , E ],
68
98
layer : ZLayer [R1 & ServerRequest , TapirResponse , R ]
0 commit comments