Skip to content

Commit

Permalink
Fix variable parsing from query params in ZIO HTTP Adapter (#1118)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdogpr authored Oct 30, 2021
1 parent 8b52305 commit 47a0258
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 0 additions & 10 deletions adapters/http4s/src/main/scala/caliban/Http4sAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ object Http4sAdapter {
.foldCause(cause => GraphQLResponse(NullValue, cause.defects).asJson, _.asJson)
.provideSomeLayer[R](fileHandle)

@deprecated("Use makeHttpService instead", "0.4.0")
def makeRestService[R, E](interpreter: GraphQLInterpreter[R, E]): HttpRoutes[RIO[R, *]] =
makeHttpService(interpreter)

private def getGraphQLRequest(
query: String,
op: Option[String] = None,
Expand Down Expand Up @@ -553,12 +549,6 @@ object Http4sAdapter {
)
)

@deprecated("Use makeHttpServiceF instead", "0.4.0")
def makeRestServiceF[F[_], E](
interpreter: GraphQLInterpreter[Any, E]
)(implicit F: Async[F], dispatcher: Dispatcher[F], runtime: Runtime[Any]): HttpRoutes[F] =
makeHttpServiceF(interpreter)

def makeHttpServiceF[F[_], R, E](
interpreter: GraphQLInterpreter[R, E],
skipValidation: Boolean = false,
Expand Down
14 changes: 10 additions & 4 deletions adapters/zio-http/src/main/scala/caliban/ZHttpAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,16 @@ object ZHttpAdapter {
}

private def queryFromQueryParams(req: Request) = {
val params = List("query", "operationName", "variables", "extensions").collect { case k =>
k -> req.url.queryParams.get(k).flatMap(_.headOption).getOrElse("")
}.toMap
ZIO.fromEither(decode[GraphQLRequest](params.asJson.noSpaces))
val variablesJs = req.url.queryParams.get("variables").flatMap(_.headOption).flatMap(parse(_).toOption)
val extensionsJs = req.url.queryParams.get("extensions").flatMap(_.headOption).flatMap(parse(_).toOption)
val fields = List(
"query" -> Json.fromString(req.url.queryParams.get("query").flatMap(_.headOption).getOrElse(""))
) ++
req.url.queryParams.get("operationName").flatMap(_.headOption).map(o => "operationName" -> Json.fromString(o)) ++
variablesJs.map(js => "variables" -> js) ++
extensionsJs.map(js => "extensions" -> js)

ZIO.fromEither(Json.fromFields(fields).as[GraphQLRequest])
}

private def queryFromRequest(req: Request) =
Expand Down

0 comments on commit 47a0258

Please sign in to comment.