| 710 | * sharing its key. |
| 711 | */ |
| 712 | const callBatch = <Op extends GraphQL.Any, K>( |
| 713 | method: OperationMethod<Op>, |
| 714 | entries: Arr.NonEmptyArray<Request.Entry<KeyRequest<K, any, any, any>>>, |
| 715 | variables: (keys: ReadonlyArray<K>) => GraphQL.Variables<Op> |
| 716 | ) => { |
| 717 | const keys: Array<K> = [] |
| 718 | const targets: Array<Request.Entry<KeyRequest<K, any, any, any>>> = [] |
| 719 | const indices = MutableHashMap.empty<K, number>() |
| 720 | for (const entry of entries) { |
| 721 | const index = MutableHashMap.get(indices, entry.request.key) |
| 722 | if (index._tag === "None") { |
| 723 | MutableHashMap.set(indices, entry.request.key, keys.length) |
| 724 | keys.push(entry.request.key) |
| 725 | targets.push(entry) |
| 726 | continue |
| 727 | } |
| 728 | const previous = targets[index.value] |
| 729 | targets[index.value] = { |
| 730 | ...previous, |
| 731 | completeUnsafe(exit) { |
| 732 | previous.completeUnsafe(exit) |
| 733 | entry.completeUnsafe(exit) |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | // Generic conditional parameters prevent calling the partial overload directly. |
| 738 | const call = method as unknown as ( |
| 739 | variables: GraphQL.Variables<Op>, |
| 740 | options: { readonly partial: true } |
| 741 | ) => Effect.Effect<PartialResult<GraphQL.Result<Op>>, GraphQL.Error<Op>, GraphQL.Services<Op>> |
| 742 | return Effect.map(call(variables(keys), { partial: true }), (result) => ({ keys, targets, result })) |
| 743 | } |
| 744 | |
| 745 | // Fails the batch with the response's errors and transport metadata. |
| 746 | const batchError = ( |