Skip to content

Commit

Permalink
Update zio-query and use ZQuery.fromZIONow in hotpath methods (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Mar 29, 2024
1 parent e6eb7cf commit 7ddba86
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ 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.0"
val zqueryVersion = "0.6.1"
val zioJsonVersion = "0.6.2"
val zioHttpVersion = "3.0.0-RC4"
val zioOpenTelemetryVersion = "3.0.0-RC21"
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/caliban/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ object Executor {
)
} else {
reduceStep(
QueryStep(ZQuery.fromZIO(stream.runCollect.map(chunk => ListStep(chunk.toList)))),
QueryStep(ZQuery.fromZIONow(stream.runCollect.map(chunk => ListStep(chunk.toList)))),
currentField,
arguments,
path
Expand Down Expand Up @@ -382,7 +382,7 @@ object Executor {
): URQuery[R, ResponseValue] = {

def handleError(error: ExecutionError): UQuery[ResponseValue] =
ZQuery.fromZIO(errors.update(error :: _).as(NullValue))
ZQuery.fromZIONow(errors.update(error :: _).as(NullValue))

def wrap(query: ExecutionQuery[ResponseValue], isPure: Boolean, fieldInfo: FieldInfo) = {
@tailrec
Expand Down Expand Up @@ -494,7 +494,7 @@ object Executor {
val deferredSteps = nextSteps.map { case (step, label) =>
Deferred(path, step, label)
}
ZQuery.fromZIO(deferred.update(deferredSteps ::: _)) *> loop(obj)
ZQuery.fromZIONow(deferred.update(deferredSteps ::: _)) *> loop(obj)
}

loop(step, isTopLevelField = true).catchAll(handleError)
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/caliban/schema/Schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,15 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema {
new Schema[R0, URIO[R1, A]] {
override def optional: Boolean = ev.optional
override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription)
override def resolve(value: URIO[R1, A]): Step[R0] = QueryStep(ZQuery.fromZIO(value.map(ev.resolve)))
override def resolve(value: URIO[R1, A]): Step[R0] = QueryStep(ZQuery.fromZIONow(value.map(ev.resolve)))
}
implicit def effectSchema[R0, R1 >: R0, R2 >: R0, E <: Throwable, A](implicit
ev: Schema[R2, A]
): Schema[R0, ZIO[R1, E, A]] =
new Schema[R0, ZIO[R1, E, A]] {
override def optional: Boolean = true
override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription)
override def resolve(value: ZIO[R1, E, A]): Step[R0] = QueryStep(ZQuery.fromZIO(value.map(ev.resolve)))
override def resolve(value: ZIO[R1, E, A]): Step[R0] = QueryStep(ZQuery.fromZIONow(value.map(ev.resolve)))
}
def customErrorEffectSchema[R0, R1 >: R0, R2 >: R0, E, A](convertError: E => ExecutionError)(implicit
ev: Schema[R2, A]
Expand All @@ -514,7 +514,7 @@ trait GenericSchema[R] extends SchemaDerivation[R] with TemporalSchema {
override def optional: Boolean = true
override def toType(isInput: Boolean, isSubscription: Boolean): __Type = ev.toType_(isInput, isSubscription)
override def resolve(value: ZIO[R1, E, A]): Step[R0] = QueryStep(
ZQuery.fromZIO(value.mapBoth(convertError, ev.resolve))
ZQuery.fromZIONow(value.mapBoth(convertError, ev.resolve))
)
}
implicit def infallibleQuerySchema[R0, R1 >: R0, R2 >: R0, A](implicit
Expand Down
14 changes: 8 additions & 6 deletions tracing/src/main/scala/caliban/tracing/FieldTracer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ object FieldTracer {
): ZQuery[R, CalibanError.ExecutionError, ResponseValue] =
ZQuery.acquireReleaseWith(
ZIO.serviceWithZIO[Tracing](_.spanUnsafe(info.name))
) { case (span, end) => end } { case (span, _) =>
) { case (_, end) => end } { case (span, _) =>
query.foldCauseQuery(
cause => {
val status =
cause.failureOption.flatMap(StatusMapper.default.failure.lift).fold(StatusCode.ERROR)(_.statusCode)
ZQuery.fromZIO(ZIO.succeed(span.setStatus(status, cause.prettyPrint))) *> ZQuery.failCause(cause)
},
cause =>
ZQuery.failCause {
val status =
cause.failureOption.flatMap(StatusMapper.default.failure.lift).fold(StatusCode.ERROR)(_.statusCode)
span.setStatus(status, cause.prettyPrint)
cause
},
value => ZQuery.succeed(value)
)
}
Expand Down

0 comments on commit 7ddba86

Please sign in to comment.