diff --git a/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala b/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala index 30e381c9b2..562abe5663 100644 --- a/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala +++ b/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala @@ -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,13 +93,9 @@ 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() @@ -108,7 +103,7 @@ final private class QuickRequestHandler[R]( 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( diff --git a/build.sbt b/build.sbt index 11a2ee63b4..6eb9621f08 100644 --- a/build.sbt +++ b/build.sbt @@ -23,7 +23,7 @@ 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" @@ -31,7 +31,7 @@ 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"