batchByCustomGrouping

suspend fun <T : NodeObject, C : SelectiveNodeExecutionContext<T>, K> batchByCustomGrouping(contexts: List<C>, groupBy: (SelectionSet<T>) -> K, resolve: suspend (Group<T, C, K>) -> Map<C, FieldValue<T>>): Map<C, FieldValue<T>>(source)

Partitions contexts by a tenant-defined key derived from each context's selection set.

  • Group.contexts keeps the input order.

  • Blocks for different groups may run concurrently, so resolve should not mutate shared state.

  • resolve should return a value for every context in its group. If it leaves one out, that context is missing from the result and Viaduct fails the whole batch.

  • If a block throws an exception or times out, every context in its group gets an error. Other groups are not affected.

  • If the caller is cancelled or groupBy throws, the whole call fails.