(
method: OperationMethod<Op>,
options: {
readonly variables: (keys: ReadonlyArray<K>) => GraphQL.Variables<Op>
readonly path: Path<GraphQL.Result<Op>, P>
readonly key: (item: Narrow<Item<GraphQL.Result<Op>, P>, T>) => K
readonly typename?: T | undefined
} & BatchKey<Op>
)
| 370 | * @since 4.0.0 |
| 371 | */ |
| 372 | export const findById = < |
| 373 | Op extends GraphQL.Any, |
| 374 | K, |
| 375 | const P extends ReadonlyArray<string>, |
| 376 | T extends Typenames<Item<GraphQL.Result<Op>, P>> = never |
| 377 | >( |
| 378 | method: OperationMethod<Op>, |
| 379 | options: { |
| 380 | readonly variables: (keys: ReadonlyArray<K>) => GraphQL.Variables<Op> |
| 381 | readonly path: Path<GraphQL.Result<Op>, P> |
| 382 | readonly key: (item: Narrow<Item<GraphQL.Result<Op>, P>, T>) => K |
| 383 | readonly typename?: T | undefined |
| 384 | } & BatchKey<Op> |
| 385 | ): RequestResolver.RequestResolver< |
| 386 | KeyRequest< |
| 387 | K, |
| 388 | Narrow<Item<GraphQL.Result<Op>, P>, T>, |
| 389 | GraphQL.Error<Op> | Cause.NoSuchElementError, |
| 390 | GraphQL.Services<Op> |
| 391 | > |
| 392 | > => { |
| 393 | const path = options.path as ReadonlyArray<string> |
| 394 | const codec = internalGraphQL.makeCodec(method.operation) |
| 395 | return makeResolver( |
| 396 | method, |
| 397 | options.batchKey, |
| 398 | (entries) => |
| 399 | Effect.flatMap(callBatch(method, entries, options.variables), ({ keys, targets, result }) => { |
| 400 | if (result.errors.length > 0) return batchError(codec, result) |
| 401 | const list = findList(result.data, path) |
| 402 | if (list === undefined) return completeAll(targets) |
| 403 | if (list.truncated) return Effect.fail(codec.fail(truncated(path))) |
| 404 | const pending = MutableHashMap.empty<K, Request.Entry<any>>() |
| 405 | for (let i = 0; i < keys.length; i++) MutableHashMap.set(pending, keys[i], targets[i]) |
| 406 | for (const item of list.items) { |
| 407 | if (!matchesTypename(item, options.typename)) continue |
| 408 | const key = options.key(item as Narrow<Item<GraphQL.Result<Op>, P>, T>) |
| 409 | const target = MutableHashMap.get(pending, key) |
| 410 | if (target._tag === "None") continue |
| 411 | MutableHashMap.remove(pending, key) |
| 412 | target.value.completeUnsafe(Exit.succeed(item)) |
| 413 | } |
| 414 | MutableHashMap.forEach(pending, (target) => target.completeUnsafe(constNoSuchElement)) |
| 415 | return Effect.void |
| 416 | }) |
| 417 | ) |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Batches calls to a generated query or mutation by repeating the operation |
nothing calls this directly
no test coverage detected