Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mixed query execution mode #2129

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}