Skip to content

Commit

Permalink
Update zio-http to 3.0.0-RC6 (#2159)
Browse files Browse the repository at this point in the history
* Update zio-http to RC5 (caliban-quick)

* Update to zio-http RC6
  • Loading branch information
kyri-petrou authored Apr 8, 2024
1 parent 79e363a commit 5305eda
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import com.github.plokhotnyuk.jsoniter_scala.core._
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
import zio._
import zio.http.ChannelEvent.UserEvent.HandshakeComplete
import zio.http.Header.ContentType
import zio.http._
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.stream.{ UStream, ZPipeline, ZStream }
@@ -70,15 +69,15 @@ final private class QuickRequestHandler[R](

def decodeQueryParams(queryParams: QueryParams): Either[Response, GraphQLRequest] = {
def extractField(key: String) =
try Right(queryParams.get(key).map(readFromString[InputValue.ObjectValue](_).fields))
try Right(queryParams.getAll(key).headOption.map(readFromString[InputValue.ObjectValue](_).fields))
catch { case NonFatal(_) => Left(badRequest(s"Invalid $key query param")) }

for {
vars <- extractField("variables")
exts <- extractField("extensions")
} yield GraphQLRequest(
query = queryParams.get("query"),
operationName = queryParams.get("operationName"),
query = queryParams.getAll("query").headOption,
operationName = queryParams.getAll("operationName").headOption,
variables = vars,
extensions = exts
)
@@ -94,21 +93,17 @@ final private class QuickRequestHandler[R](
.orElseFail(BodyDecodeErrorResponse)

val isApplicationGql =
httpReq.headers.get(ContentType.name).exists { h =>
h.length >= 19 && { // Length of "application/graphql"
MediaType.forContentType(h).exists { mt =>
mt.subType.equalsIgnoreCase("graphql") &&
mt.mainType.equalsIgnoreCase("application")
}
}
httpReq.body.mediaType.exists { mt =>
mt.subType.equalsIgnoreCase("graphql") &&
mt.mainType.equalsIgnoreCase("application")
}

if (isApplicationGql) decodeApplicationGql() else decodeJson()
}

val queryParams = httpReq.url.queryParams

(if (httpReq.method == Method.GET || queryParams.get("query").isDefined) {
(if ((httpReq.method eq Method.GET) || queryParams.hasQueryParam("query")) {
ZIO.fromEither(decodeQueryParams(queryParams))
} else {
val req = decodeBody(httpReq.body)
@@ -177,7 +172,7 @@ final private class QuickRequestHandler[R](
Response(
Status.Ok,
headers = responseHeaders(ContentTypeMultipart, None),
body = Body.fromStream(encodeMultipartMixedResponse(resp, stream))
body = Body.fromStreamChunked(encodeMultipartMixedResponse(resp, stream))
)
case resp if accepts.serverSentEvents =>
Response.fromServerSentEvents(encodeTextEventStream(resp))
@@ -207,7 +202,7 @@ final private class QuickRequestHandler[R](
hasCacheDirective: Boolean
): Body = {
val excludeExtensions = if (hasCacheDirective) Some(Set(Caching.DirectiveName)) else None
Body.fromChunk(Chunk.fromArray(writeToArray(resp.toResponseValue(keepDataOnErrors, excludeExtensions))))
Body.fromArray(writeToArray(resp.toResponseValue(keepDataOnErrors, excludeExtensions)))
}

private def encodeMultipartMixedResponse(
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@ val playVersion = "3.0.2"
val playJsonVersion = "3.0.2"
val scalafmtVersion = "3.8.0"
val sttpVersion = "3.9.5"
val tapirVersion = "1.10.0"
val tapirVersion = "1.10.4"
val zioVersion = "2.0.21"
val zioInteropCats2Version = "22.0.0.0"
val zioInteropCats3Version = "23.1.0.1"
val zioInteropReactiveVersion = "2.0.2"
val zioConfigVersion = "3.0.7"
val zqueryVersion = "0.6.1"
val zioJsonVersion = "0.6.2"
val zioHttpVersion = "3.0.0-RC4"
val zioHttpVersion = "3.0.0-RC6"
val zioOpenTelemetryVersion = "3.0.0-RC21"
val zioPreludeVersion = "1.0.0-RC23"

0 comments on commit 5305eda

Please sign in to comment.