(
method: OperationMethod<Op>,
options: {
readonly variables: (keys: ReadonlyArray<K>) => GraphQL.Variables<Op>
readonly path: Path<GraphQL.Result<Op>, P>
readonly typename?: T | undefined
} & BatchKey<Op>
)
| 237 | * @since 4.0.0 |
| 238 | */ |
| 239 | export const ordered = < |
| 240 | Op extends GraphQL.Any, |
| 241 | K, |
| 242 | const P extends ReadonlyArray<string>, |
| 243 | T extends Typenames<Item<GraphQL.Result<Op>, P>> = never |
| 244 | >( |
| 245 | method: OperationMethod<Op>, |
| 246 | options: { |
| 247 | readonly variables: (keys: ReadonlyArray<K>) => GraphQL.Variables<Op> |
| 248 | readonly path: Path<GraphQL.Result<Op>, P> |
| 249 | readonly typename?: T | undefined |
| 250 | } & BatchKey<Op> |
| 251 | ): RequestResolver.RequestResolver< |
| 252 | KeyRequest< |
| 253 | K, |
| 254 | Narrow<Item<GraphQL.Result<Op>, P>, T>, |
| 255 | GraphQL.Error<Op> | Cause.NoSuchElementError, |
| 256 | GraphQL.Services<Op> |
| 257 | > |
| 258 | > => { |
| 259 | const path = options.path as ReadonlyArray<string> |
| 260 | const codec = internalGraphQL.makeCodec(method.operation) |
| 261 | return makeResolver( |
| 262 | method, |
| 263 | options.batchKey, |
| 264 | (entries) => |
| 265 | Effect.flatMap(callBatch(method, entries, options.variables), ({ keys, targets, result }) => { |
| 266 | const byIndex = new Map<number, Arr.NonEmptyArray<GraphQLError>>() |
| 267 | for (const error of result.errors) { |
| 268 | const index = entryIndex(error, path, keys.length) |
| 269 | if (index === undefined) return batchError(codec, result) |
| 270 | const errors = byIndex.get(index) |
| 271 | if (errors === undefined) byIndex.set(index, [error]) |
| 272 | else errors.push(error) |
| 273 | } |
| 274 | const list = findList(result.data, path) |
| 275 | // An error in a non-null item nulls the whole list, so every entry lost its data to it. |
| 276 | if (list === undefined) return result.errors.length > 0 ? batchError(codec, result) : completeAll(targets) |
| 277 | if (list.truncated) return Effect.fail(codec.fail(truncated(path))) |
| 278 | if (list.items.length !== keys.length) { |
| 279 | return Effect.fail(codec.fail( |
| 280 | new DecodeError({ |
| 281 | description: `Expected ${keys.length} entries at ${path.join(".")}, received ${list.items.length}` |
| 282 | }) |
| 283 | )) |
| 284 | } |
| 285 | const response = internalGraphQL.partialResponses.get(result) |
| 286 | for (let i = 0; i < targets.length; i++) { |
| 287 | const errors = byIndex.get(i) |
| 288 | const item = list.items[i] |
| 289 | targets[i].completeUnsafe( |
| 290 | errors !== undefined |
| 291 | ? Exit.fail(codec.fail( |
| 292 | internalGraphQL.responseError({ status: response?.status, headers: response?.headers }, errors) |
| 293 | )) |
| 294 | : matchesTypename(item, options.typename) |
| 295 | ? Exit.succeed(item) |
| 296 | : constNoSuchElement |
nothing calls this directly
no test coverage detected