{"version":3,"file":"legacyExecuteIncrementally.js","sourceRoot":"","sources":["../../../src/execution/legacyIncremental/legacyExecuteIncrementally.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,uBAAsB;AAQtD,OAAO,EAAE,4BAA4B,EAAE,2CAA0C;AAoIjF,MAAM,UAAU,0BAA0B,CACxC,IAAmB;IAMnB,MAAM,sBAAsB,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAG3D,IAAI,CAAC,CAAC,QAAQ,IAAI,sBAAsB,CAAC,EAAE,CAAC;QAC1C,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;IAC5C,CAAC;IAED,OAAO,6BAA6B,CAAC,sBAAsB,CAAC,CAAC;AAC/D,CAAC;AA8BD,MAAM,UAAU,6BAA6B,CAC3C,sBAA8C;IAI9C,OAAO,IAAI,4BAA4B,CACrC,sBAAsB,CACvB,CAAC,uBAAuB,EAAE,CAAC;AAC9B,CAAC","sourcesContent":["/** @category Legacy Incremental Execution */\n\nimport type { PromiseOrValue } from '../../jsutils/PromiseOrValue.ts';\n\nimport { validateExecutionArgs } from '../execute.ts';\nimport type {\n  ExecutionArgs,\n  ValidatedExecutionArgs,\n} from '../ExecutionArgs.ts';\nimport type { ExecutionResult } from '../Executor.ts';\n\nimport type { LegacyExperimentalIncrementalExecutionResults } from './BranchingIncrementalExecutor.ts';\nimport { BranchingIncrementalExecutor } from './BranchingIncrementalExecutor.ts';\n\n/**\n * Executes a GraphQL operation with support for `@defer` and `@stream` using\n * the legacy incremental delivery payload format.\n *\n * Prefer `experimentalExecuteIncrementally` for the current incremental\n * delivery format. In the legacy format, each subsequent incremental payload\n * identifies its location with `path` and optional `label` fields. The current\n * format instead tracks pending work by `id` and reports completion through\n * `completed` entries.\n * @param args - Execution arguments for the GraphQL operation.\n * @returns A single execution result or legacy incremental execution results.\n * @example\n * ```ts\n * import assert from 'node:assert';\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import { legacyExecuteIncrementally } from 'graphql/execution';\n *\n * const schema = buildSchema(`\n *   type Query {\n *     hero: Hero\n *   }\n *\n *   type Hero {\n *     id: ID!\n *     name: String!\n *   }\n * `);\n *\n * const result = await legacyExecuteIncrementally({\n *   schema,\n *   document: parse('{ hero { id ... @defer(label: \"HeroName\") { name } } }'),\n *   rootValue: { hero: { id: '1', name: 'Luke' } },\n * });\n *\n * assert('initialResult' in result);\n *\n * result.initialResult; // => { data: { hero: { id: '1' } }, hasNext: true }\n *\n * const deferred = await result.subsequentResults.next();\n * deferred.value; // => { incremental: [ { data: { name: 'Luke' }, path: ['hero'], label: 'HeroName' } ], hasNext: false }\n * ```\n * @example\n * Compare the legacy payload format with the current incremental delivery\n * format returned by `experimentalExecuteIncrementally`.\n * ```ts\n * import assert from 'node:assert';\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import {\n *   experimentalExecuteIncrementally,\n *   legacyExecuteIncrementally,\n * } from 'graphql/execution';\n *\n * const schema = buildSchema(`\n *   type Query {\n *     hero: Hero\n *   }\n *\n *   type Hero {\n *     id: ID!\n *     name: String!\n *   }\n * `);\n * const document = parse('{ hero { id ... @defer { name } } }');\n * const rootValue = { hero: { id: '1', name: 'Luke' } };\n *\n * const experimental = await experimentalExecuteIncrementally({\n *   schema,\n *   document,\n *   rootValue,\n * });\n * const legacy = await legacyExecuteIncrementally({\n *   schema,\n *   document,\n *   rootValue,\n * });\n *\n * assert('initialResult' in experimental);\n * assert('initialResult' in legacy);\n *\n * experimental.initialResult; // => { data: { hero: { id: '1' } }, pending: [ { id: '0', path: ['hero'] } ], hasNext: true }\n * legacy.initialResult; // => { data: { hero: { id: '1' } }, hasNext: true }\n *\n * const experimentalDeferred = await experimental.subsequentResults.next();\n * experimentalDeferred.value; // => { incremental: [{ data: { name: 'Luke' }, id: '0' }], completed: [{ id: '0' }], hasNext: false }\n *\n * const legacyDeferred = await legacy.subsequentResults.next();\n * legacyDeferred.value; // => { incremental: [ { data: { name: 'Luke' }, path: ['hero'] } ], hasNext: false }\n * ```\n * @example\n * Compare streamed list payloads in the legacy and current incremental\n * delivery formats.\n * ```ts\n * import assert from 'node:assert';\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import {\n *   experimentalExecuteIncrementally,\n *   legacyExecuteIncrementally,\n * } from 'graphql/execution';\n *\n * const schema = buildSchema('type Query { colors: [String] }');\n * const document = parse('{ colors @stream(initialCount: 1) }');\n * const rootValue = { colors: ['red', 'green', 'blue'] };\n *\n * const experimental = await experimentalExecuteIncrementally({\n *   schema,\n *   document,\n *   rootValue,\n * });\n * const legacy = await legacyExecuteIncrementally({\n *   schema,\n *   document,\n *   rootValue,\n * });\n *\n * assert('initialResult' in experimental);\n * assert('initialResult' in legacy);\n *\n * experimental.initialResult; // => { data: { colors: ['red'] }, pending: [ { id: '0', path: ['colors'] } ], hasNext: true }\n * legacy.initialResult; // => { data: { colors: ['red'] }, hasNext: true }\n *\n * const experimentalStream = await experimental.subsequentResults.next();\n * experimentalStream.value; // => { incremental: [ { items: ['green', 'blue'], id: '0' } ], completed: [{ id: '0' }], hasNext: false }\n *\n * const legacyStream = await legacy.subsequentResults.next();\n * legacyStream.value; // => { incremental: [ { items: ['green', 'blue'], path: ['colors', 1] } ], hasNext: false }\n * ```\n */\nexport function legacyExecuteIncrementally(\n  args: ExecutionArgs,\n): PromiseOrValue<\n  ExecutionResult | LegacyExperimentalIncrementalExecutionResults\n> {\n  // If a valid execution context cannot be created due to incorrect arguments,\n  // a \"Response\" with only errors is returned.\n  const validatedExecutionArgs = validateExecutionArgs(args);\n\n  // Return early errors if execution context failed.\n  if (!('schema' in validatedExecutionArgs)) {\n    return { errors: validatedExecutionArgs };\n  }\n\n  return legacyExecuteRootSelectionSet(validatedExecutionArgs);\n}\n\n/**\n * Executes a validated operation root selection set with support for `@defer`\n * and `@stream` using the legacy incremental delivery payload format.\n * @param validatedExecutionArgs - Validated execution arguments.\n * @returns A single execution result or legacy incremental execution results.\n * @example\n * ```ts\n * import assert from 'node:assert';\n * import { parse } from 'graphql/language';\n * import { buildSchema } from 'graphql/utilities';\n * import {\n *   legacyExecuteRootSelectionSet,\n *   validateExecutionArgs,\n * } from 'graphql/execution';\n *\n * const schema = buildSchema('type Query { greeting: String }');\n * const validatedArgs = validateExecutionArgs({\n *   schema,\n *   document: parse('{ greeting }'),\n *   rootValue: { greeting: 'Hello' },\n * });\n *\n * assert('schema' in validatedArgs);\n *\n * const result = await legacyExecuteRootSelectionSet(validatedArgs);\n * result; // => { data: { greeting: 'Hello' } }\n * ```\n */\nexport function legacyExecuteRootSelectionSet(\n  validatedExecutionArgs: ValidatedExecutionArgs,\n): PromiseOrValue<\n  ExecutionResult | LegacyExperimentalIncrementalExecutionResults\n> {\n  return new BranchingIncrementalExecutor(\n    validatedExecutionArgs,\n  ).executeRootSelectionSet();\n}\n"]}