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

Update zio-http to 3.0.0-RC6 #2159

Merged
merged 3 commits into from
Apr 8, 2024
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
23 changes: 9 additions & 14 deletions adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down