From d6ec90fb177daf93f6ada5e5e53c0f7dd9137b10 Mon Sep 17 00:00:00 2001 From: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Fri, 23 Feb 2024 14:46:54 +1100 Subject: [PATCH] Add Mixed query execution mode (#2129) --- core/src/main/scala/caliban/execution/Executor.scala | 3 +++ .../src/main/scala/caliban/execution/QueryExecution.scala | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/caliban/execution/Executor.scala b/core/src/main/scala/caliban/execution/Executor.scala index 2329f4387..73d6cf0f0 100644 --- a/core/src/main/scala/caliban/execution/Executor.scala +++ b/core/src/main/scala/caliban/execution/Executor.scala @@ -58,6 +58,9 @@ object Executor { case QueryExecution.Batched => ZQuery.foreachBatched(in)(as) case QueryExecution.Parallel => ZQuery.foreachPar(in)(as) case QueryExecution.Sequential => ZQuery.foreach(in)(as) + case QueryExecution.Mixed => + if (isTopLevelField) ZQuery.foreachPar(in)(as) + else ZQuery.foreachBatched(in)(as) } } diff --git a/core/src/main/scala/caliban/execution/QueryExecution.scala b/core/src/main/scala/caliban/execution/QueryExecution.scala index 7716b4abb..d79ccc08f 100644 --- a/core/src/main/scala/caliban/execution/QueryExecution.scala +++ b/core/src/main/scala/caliban/execution/QueryExecution.scala @@ -19,7 +19,13 @@ object QueryExecution { /** * Run effectful fields sequentially but batch effects wrapped with `ZQuery.fromRequest`. - * This mode is recommended when most of your effects are relying on ZQuery as it avoids forking unnecessary fibers. + * This mode is recommended when most of your effects are backed by ZQuery DataSources as it avoids forking unnecessary fibers. */ case object Batched extends QueryExecution + + /** + * Run effectful top-level fields in [[Parallel]] mode and nested fields in [[Batched]] mode. + * This mode is recommended when most of your effects are backed by ZQuery DataSources but want to guarantee that top-level fields are always executed in parallel. + */ + case object Mixed extends QueryExecution }