MCPcopy Create free account
hub / github.com/Effect-TS/effect / callBatch

Function callBatch

packages/effect/src/graphql/GraphQLResolver.ts:712–743  ·  view source on GitHub ↗
(
  method: OperationMethod<Op>,
  entries: Arr.NonEmptyArray<Request.Entry<KeyRequest<K, any, any, any>>>,
  variables: (keys: ReadonlyArray<K>) => GraphQL.Variables<Op>
)

Source from the content-addressed store, hash-verified

710 * sharing its key.
711 */
712const 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.
746const batchError = (

Callers 2

orderedFunction · 0.85
findByIdFunction · 0.85

Calls 6

variablesFunction · 0.85
callFunction · 0.70
getMethod · 0.65
setMethod · 0.65
pushMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected