Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variable parsing from query params in ZIO HTTP Adapter #1118

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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