Skip to content

Commit

Permalink
Unify toApp implementations (#2030)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Dec 7, 2023
1 parent 2a9d4fb commit 1062138
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions adapters/quick/src/main/scala/caliban/QuickAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ final class QuickAdapter[-R, E] private (requestHandler: QuickRequestHandler[R,
* @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.
*/
def toApp(apiPath: Path, graphiqlPath: Option[Path] = None): HttpApp[R] = {
def toApp(apiPath: String, graphiqlPath: Option[String] = None): HttpApp[R] = {
val apiRoutes = List(
RoutePattern(Method.POST, apiPath) -> handler,
RoutePattern(Method.GET, apiPath) -> handler
)
val graphiqlRoute = graphiqlPath.fold(List.empty[Route[R, Nothing]]) { uiPath =>
val uiHandler = GraphiQLHandler.handler(apiPath.toString(), uiPath.toString)
val uiHandler = GraphiQLHandler.handler(apiPath, uiPath)
List(RoutePattern(Method.GET, uiPath) -> uiHandler)
}

Expand All @@ -43,7 +43,7 @@ final class QuickAdapter[-R, E] private (requestHandler: QuickRequestHandler[R,
trace: Trace
): RIO[R, Nothing] =
Server
.serve[R](toApp(Path.decode(apiPath), graphiqlPath.map(Path.decode)))
.serve[R](toApp(apiPath, graphiqlPath))
.provideSomeLayer[R](Server.defaultWithPort(port))

def configure(config: ExecutionConfiguration)(implicit trace: Trace): QuickAdapter[R, E] =
Expand Down
2 changes: 1 addition & 1 deletion adapters/quick/src/main/scala/caliban/quick/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ package object quick {
def toApp(apiPath: String, graphiqlPath: Option[String] = None)(implicit
trace: Trace
): RIO[R, HttpApp[R]] =
gql.interpreter.map(QuickAdapter(_).toApp(Path.decode(apiPath), graphiqlPath.map(Path.decode)))
gql.interpreter.map(QuickAdapter(_).toApp(apiPath, graphiqlPath))

/**
* Creates a zio-http handler for the GraphQL API
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ lazy val enableMimaSettingsJVM =
ProblemFilters.exclude[IncompatibleResultTypeProblem]("caliban.schema.Step#ObjectStep*"),
ProblemFilters.exclude[DirectMissingMethodProblem]("caliban.schema.Annotations*"),
ProblemFilters.exclude[MissingTypesProblem]("caliban.schema.Annotations*"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("caliban.schema.Annotations*")
ProblemFilters.exclude[IncompatibleResultTypeProblem]("caliban.schema.Annotations*"),
ProblemFilters.exclude[IncompatibleMethTypeProblem]("caliban.QuickAdapter.toApp")
)
)

Expand Down

0 comments on commit 1062138

Please sign in to comment.