Skip to content

Commit

Permalink
Update zio-query and use fold over catchAllZIO (#2402)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Sep 15, 2024
1 parent 18dada3 commit 0ad80a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 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.3"
val zioInteropReactiveVersion = "2.0.2"
val zioConfigVersion = "4.0.2"
val zqueryVersion = "0.7.5"
val zqueryVersion = "0.7.6"
val zioJsonVersion = "0.7.3"
val zioHttpVersion = "3.0.0"
val zioOpenTelemetryVersion = "3.0.0-RC21"
Expand Down
17 changes: 10 additions & 7 deletions core/src/main/scala/caliban/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ object Executor {
deferred: AtomicReference[List[Deferred[R]]]
): URQuery[R, ResponseValue] = {

def handleError(error: ExecutionError): UQuery[ResponseValue] = {
def handleError(error: ExecutionError): ResponseValue = {
errors.updateAndGet(error :: _)
nullValueQuery
NullValue
}

def wrap(query: ExecutionQuery[ResponseValue], isPure: Boolean, fieldInfo: FieldInfo) = {
Expand Down Expand Up @@ -420,7 +420,7 @@ object Executor {

def objectFieldQuery(step: ReducedStep[R], info: FieldInfo, isPure: Boolean = false) = {
val q = wrap(loop(step), isPure, info)
if (info.details.fieldType.isNullable) q.catchAll(handleError) else q
if (info.details.fieldType.isNullable) q.fold(handleError, identity) else q
}

def makeObjectQuery(
Expand Down Expand Up @@ -504,7 +504,10 @@ object Executor {
}

def makeListQuery(steps: List[ReducedStep[R]], areItemsNullable: Boolean): ExecutionQuery[ResponseValue] =
collectAll(steps, isTopLevelField = false)(if (areItemsNullable) loop(_).catchAll(handleError) else loop(_))
collectAll(steps, isTopLevelField = false)(
if (areItemsNullable) loop(_).fold(handleError, identity)
else loop(_)
)
.map(ListValue.apply)

def loop(step: ReducedStep[R], isTopLevelField: Boolean = false): ExecutionQuery[ResponseValue] =
Expand All @@ -518,7 +521,7 @@ object Executor {
.environmentWith[R](env =>
ResponseValue.StreamValue(
stream.mapChunksZIO { chunk =>
collectAll(chunk, isTopLevelField)(loop(_).catchAll(_ => nullValueQuery)).run
collectAll(chunk, isTopLevelField)(loop(_).catchAllZIO(_ => nullValueExit)).run
}.provideEnvironment(env)
)
)
Expand All @@ -530,7 +533,7 @@ object Executor {
loop(obj)
}

loop(step, isTopLevelField = true).catchAll(handleError)
loop(step, isTopLevelField = true).fold(handleError, identity)
}
}

Expand All @@ -546,7 +549,7 @@ object Executor {
case other => Cause.fail(ExecutionError("Effect failure", path.reverse, locationInfo, other))
}

private val nullValueQuery = ZQuery.succeedNow(NullValue)
private val nullValueExit = Exit.succeed(NullValue)

// The implicit classes below are for methods that don't exist in Scala 2.12 so we add them as syntax methods instead
private implicit class EnrichedListOps[+A](private val list: List[A]) extends AnyVal {
Expand Down

0 comments on commit 0ad80a8

Please sign in to comment.