/** @category Incremental Execution */ import type { ObjMap } from "../../jsutils/ObjMap.js"; import type { Path } from "../../jsutils/Path.js"; import type { PromiseOrValue } from "../../jsutils/PromiseOrValue.js"; import type { GraphQLError, GraphQLFormattedError } from "../../error/GraphQLError.js"; import type { GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo } from "../../type/definition.js"; import type { DeferUsage, FieldDetailsList, GroupedFieldSet } from "../collectFields.js"; import type { SharedExecutionContext } from "../createSharedExecutionContext.js"; import type { ValidatedExecutionArgs } from "../ExecutionArgs.js"; import type { ExecutionResult, FormattedExecutionResult } from "../Executor.js"; import { Executor } from "../Executor.js"; import type { StreamUsage } from "../getStreamUsage.js"; import type { DeferUsageSet, ExecutionPlan } from "./buildExecutionPlan.js"; import { Computation } from "./Computation.js"; import { Queue } from "./Queue.js"; import type { Group, Stream, Task, Work } from "./WorkQueue.js"; /** * Results for an operation that produced incremental payloads. * @typeParam TInitialData - Shape of the initial result data payload. * @typeParam TDeferredData - Shape of deferred fragment data payloads. * @typeParam TStreamItem - Shape of streamed list items. * @typeParam TExtensions - Shape of extensions payloads. */ export interface ExperimentalIncrementalExecutionResults, TDeferredData = ObjMap, TStreamItem = unknown, TExtensions = ObjMap> { /** Initial execution result delivered before subsequent incremental payloads. */ initialResult: InitialIncrementalExecutionResult; /** Async stream of incremental payloads delivered after the initial result. */ subsequentResults: AsyncGenerator, void, void>; } /** * JSON-serializable form of incremental execution results. * @typeParam TInitial - Shape of the formatted initial result data payload. * @typeParam TDeferredData - Shape of formatted deferred fragment data payloads. * @typeParam TStreamItem - Shape of formatted streamed list items. * @typeParam TExtensions - Shape of formatted extensions payloads. */ export interface FormattedExperimentalIncrementalExecutionResults, TDeferredData = ObjMap, TStreamItem = unknown, TExtensions = ObjMap> { /** Formatted initial execution result. */ initialResult: FormattedInitialIncrementalExecutionResult; /** Async stream of formatted incremental payloads. */ subsequentResults: AsyncGenerator, void, void>; } /** * Initial execution result for an operation that produced incremental payloads. * @typeParam TData - Shape of the initial data payload. * @typeParam TExtensions - Shape of the extensions payload. */ export interface InitialIncrementalExecutionResult, TExtensions = ObjMap> extends ExecutionResult { /** Data produced by the initial execution payload. */ data: TData; /** Incremental payloads that are still pending after the initial result. */ pending: ReadonlyArray; /** Indicates that subsequent incremental payloads will follow. */ hasNext: true; /** Additional non-standard metadata included in the initial result. */ extensions?: TExtensions; } /** * JSON-serializable form of an initial incremental execution result. * @typeParam TInitialData - Shape of the formatted initial data payload. * @typeParam TExtensions - Shape of the formatted extensions payload. */ export interface FormattedInitialIncrementalExecutionResult, TExtensions = ObjMap> extends FormattedExecutionResult { /** Formatted data produced by the initial execution payload. */ data: TInitialData; /** Formatted list of incremental payloads still pending after the initial result. */ pending: ReadonlyArray; /** Indicates whether subsequent incremental payloads will follow. */ hasNext: boolean; /** Additional non-standard metadata included in the formatted initial result. */ extensions?: TExtensions; } /** * Subsequent payload produced by incremental execution. * @typeParam TDeferredData - Shape of deferred fragment data payloads. * @typeParam TStreamItem - Shape of streamed list items. * @typeParam TExtensions - Shape of the extensions payload. */ export interface SubsequentIncrementalExecutionResult, TStreamItem = unknown, TExtensions = ObjMap> { /** Incremental payloads that became pending with this response. */ pending?: ReadonlyArray; /** Deferred or streamed payloads delivered by this response. */ incremental?: ReadonlyArray>; /** Incremental payloads that completed with this response. */ completed?: ReadonlyArray; /** Indicates whether more incremental payloads will follow. */ hasNext: boolean; /** Additional non-standard metadata included in this payload. */ extensions?: TExtensions; } /** * JSON-serializable form of a subsequent incremental execution payload. * @typeParam TDeferredData - Shape of formatted deferred fragment data payloads. * @typeParam TStreamItem - Shape of formatted streamed list items. * @typeParam TExtensions - Shape of formatted extensions payloads. */ export interface FormattedSubsequentIncrementalExecutionResult, TStreamItem = unknown, TExtensions = ObjMap> { /** Indicates whether more incremental payloads will follow. */ hasNext: boolean; /** Formatted incremental payloads that became pending with this response. */ pending?: ReadonlyArray; /** Formatted deferred or streamed payloads delivered by this response. */ incremental?: ReadonlyArray>; /** Formatted incremental payloads that completed with this response. */ completed?: ReadonlyArray; /** Additional non-standard metadata included in this formatted payload. */ extensions?: TExtensions; } /** * Incremental payload produced by a deferred fragment. * @typeParam TDeferredData - Shape of deferred fragment data. * @typeParam TExtensions - Shape of extensions payloads. */ export interface IncrementalDeferResult, TExtensions = ObjMap> { /** Identifier matching this payload to a pending deferred fragment. */ id: string; /** Path from the deferred fragment location to this payload. */ subPath?: ReadonlyArray; /** Errors raised while executing the deferred fragment. */ errors?: ReadonlyArray; /** Data produced by the deferred fragment. */ data: TDeferredData; /** Additional non-standard metadata included in this payload. */ extensions?: TExtensions; } /** * JSON-serializable form of a deferred fragment payload. * @typeParam TDeferredData - Shape of formatted deferred fragment data. * @typeParam TExtensions - Shape of formatted extensions payloads. */ export interface FormattedIncrementalDeferResult, TExtensions = ObjMap> { /** Formatted errors raised while executing the deferred fragment. */ errors?: ReadonlyArray; /** Formatted data produced by the deferred fragment. */ data: TDeferredData; /** Identifier matching this payload to a pending deferred fragment. */ id: string; /** Path from the deferred fragment location to this payload. */ subPath?: ReadonlyArray; /** Additional non-standard metadata included in this formatted payload. */ extensions?: TExtensions; } /** * Incremental payload produced by a streamed list field. * @typeParam TStreamItem - Shape of streamed list items. * @typeParam TExtensions - Shape of extensions payloads. */ export interface IncrementalStreamResult> { /** Identifier matching this payload to a pending stream. */ id: string; /** Path from the streamed field location to these items. */ subPath?: ReadonlyArray; /** Errors raised while producing streamed items. */ errors?: ReadonlyArray; /** Streamed list items delivered by this payload. */ items: ReadonlyArray; /** Additional non-standard metadata included in this payload. */ extensions?: TExtensions; } /** * JSON-serializable form of a streamed list payload. * @typeParam TStreamItem - Shape of formatted streamed list items. * @typeParam TExtensions - Shape of formatted extensions payloads. */ export interface FormattedIncrementalStreamResult, TExtensions = ObjMap> { /** Formatted errors raised while producing streamed items. */ errors?: ReadonlyArray; /** Formatted streamed list items delivered by this payload. */ items: ReadonlyArray; /** Identifier matching this payload to a pending stream. */ id: string; /** Path from the streamed field location to these items. */ subPath?: ReadonlyArray; /** Additional non-standard metadata included in this formatted payload. */ extensions?: TExtensions; } /** * Deferred fragment or streamed list payload produced by incremental execution. * @typeParam TDeferredData - Shape of deferred fragment data. * @typeParam TStreamItem - Shape of streamed list items. * @typeParam TExtensions - Shape of extensions payloads. */ export type IncrementalResult, TStreamItem = unknown, TExtensions = ObjMap> = IncrementalDeferResult | IncrementalStreamResult; /** * JSON-serializable deferred fragment or streamed list payload. * @typeParam TDeferredData - Shape of formatted deferred fragment data. * @typeParam TStreamItem - Shape of formatted streamed list items. * @typeParam TExtensions - Shape of formatted extensions payloads. */ export type FormattedIncrementalResult, TStreamItem = unknown, TExtensions = ObjMap> = FormattedIncrementalDeferResult | FormattedIncrementalStreamResult; /** @internal */ export interface PendingResult { id: string; path: ReadonlyArray; label?: string; } /** @internal */ export interface CompletedResult { id: string; errors?: ReadonlyArray; } /** @internal */ export interface FormattedCompletedResult { id: string; errors?: ReadonlyArray; } interface ExecutionGroup extends Task { groups: ReadonlyArray; path: Path | undefined; computation: Computation; } /** @internal */ export interface DeliveryGroup extends Group { path: Path | undefined; label: string | undefined; parent: DeliveryGroup | undefined; } /** @internal */ export interface ItemStream extends Stream { path: Path; label: string | undefined; initialCount: number; } /** @internal */ export interface ExecutionGroupValue { deliveryGroups: ReadonlyArray; path: ReadonlyArray; errors?: ReadonlyArray; data: ObjMap; } /** @internal */ export type IncrementalWork = Work; /** @internal */ export interface ExecutionGroupResult { value: ExecutionGroupValue; work?: IncrementalWork | undefined; } /** @internal */ export interface StreamItemValue { errors?: ReadonlyArray; item: unknown; } /** @internal */ export interface StreamItemResult { value: StreamItemValue; work?: IncrementalWork | undefined; } /** @internal */ export declare class IncrementalExecutor extends Executor, TExperimental> { deferUsageSet?: DeferUsageSet | undefined; groups: Array; tasks: Array; streams: Array; constructor(validatedExecutionArgs: ValidatedExecutionArgs, sharedExecutionContext?: SharedExecutionContext, deferUsageSet?: DeferUsageSet); getCreateSubExecutor(): (deferUsageSet?: DeferUsageSet) => IncrementalExecutor; abort(reason?: unknown): void; /** * Given a completed execution context and data, build the `{ errors, data }` * response defined by the "Response" section of the GraphQL specification. * * @internal */ buildResponse(data: ObjMap | null): ExecutionResult | TExperimental; executeCollectedRootFields(rootType: GraphQLObjectType, rootValue: unknown, originalGroupedFieldSet: GroupedFieldSet, serially: boolean, newDeferUsages: ReadonlyArray): PromiseOrValue>; buildRootExecutionPlan(originalGroupedFieldSet: GroupedFieldSet): ExecutionPlan; executeCollectedSubfields(parentType: GraphQLObjectType, sourceValue: unknown, path: Path | undefined, originalGroupedFieldSet: GroupedFieldSet, newDeferUsages: ReadonlyArray, deliveryGroupMap: ReadonlyMap | undefined): PromiseOrValue>; buildSubExecutionPlan(originalGroupedFieldSet: GroupedFieldSet): ExecutionPlan; collectExecutionGroups(parentType: GraphQLObjectType, sourceValue: unknown, path: Path | undefined, newGroupedFieldSets: Map, deliveryGroupMap: ReadonlyMap): void; executeExecutionGroup(deliveryGroups: ReadonlyArray, parentType: GraphQLObjectType, sourceValue: unknown, path: Path | undefined, groupedFieldSet: GroupedFieldSet, deliveryGroupMap: ReadonlyMap): PromiseOrValue; buildExecutionGroupResult(deliveryGroups: ReadonlyArray, path: Path | undefined, result: ObjMap): ExecutionGroupResult; getIncrementalWork(): IncrementalWork; /** * Instantiates new DeliveryGroups for the given path, returning an * updated map of DeferUsage objects to DeliveryGroups. * * Note: As defer directives may be used with operations returning lists, * a DeferUsage object may correspond to many DeliveryGroups. * * @internal */ getNewDeliveryGroupMap(newDeferUsages: ReadonlyArray, deliveryGroupMap: ReadonlyMap | undefined, path: Path | undefined): { newDeliveryGroups: ReadonlyArray; newDeliveryGroupMap: ReadonlyMap; }; shouldDefer(parentDeferUsages: undefined | DeferUsageSet, deferUsages: DeferUsageSet): boolean; handleStream(index: number, path: Path, iterator: { handle: Iterator; isAsync?: never; } | { handle: AsyncIterator; isAsync: true; }, streamUsage: StreamUsage, info: GraphQLResolveInfo, itemType: GraphQLOutputType): boolean; buildStreamItemQueue(initialIndex: number, streamPath: Path, iterator: Iterator | AsyncIterator, fieldDetailsList: FieldDetailsList, info: GraphQLResolveInfo, itemType: GraphQLOutputType, isAsync: boolean | undefined): Queue; completeStreamItem(itemPath: Path, item: unknown, fieldDetailsList: FieldDetailsList, info: GraphQLResolveInfo, itemType: GraphQLOutputType): PromiseOrValue; buildStreamItemResult(result: unknown): StreamItemResult; } export {};