Skip to content

Commit

Permalink
Add Mixed query execution mode (#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou authored Feb 23, 2024
1 parent 6e3c060 commit d6ec90f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/scala/caliban/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
8 changes: 7 additions & 1 deletion core/src/main/scala/caliban/execution/QueryExecution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d6ec90f

Please sign in to comment.