diff --git a/src/execution/IncrementalPublisher.ts b/src/execution/IncrementalPublisher.ts index 3d5381e1caf..926ba08e674 100644 --- a/src/execution/IncrementalPublisher.ts +++ b/src/execution/IncrementalPublisher.ts @@ -705,14 +705,14 @@ function isStreamItemsRecord( export class InitialResultRecord { errors: Array; children: Set; + priority: number; deferPriority: number; - streamPriority: number; published: true; constructor() { this.errors = []; this.children = new Set(); + this.priority = 0; this.deferPriority = 0; - this.streamPriority = 0; this.published = true; } } @@ -720,8 +720,8 @@ export class InitialResultRecord { /** @internal */ export class DeferredGroupedFieldSetRecord { path: ReadonlyArray; + priority: number; deferPriority: number; - streamPriority: number; deferredFragmentRecords: ReadonlyArray; groupedFieldSet: GroupedFieldSet; shouldInitiateDefer: boolean; @@ -733,15 +733,15 @@ export class DeferredGroupedFieldSetRecord { constructor(opts: { path: Path | undefined; + priority: number; deferPriority: number; - streamPriority: number; deferredFragmentRecords: ReadonlyArray; groupedFieldSet: GroupedFieldSet; shouldInitiateDefer: boolean; }) { this.path = pathToArray(opts.path); + this.priority = opts.priority; this.deferPriority = opts.deferPriority; - this.streamPriority = opts.streamPriority; this.deferredFragmentRecords = opts.deferredFragmentRecords; this.groupedFieldSet = opts.groupedFieldSet; this.shouldInitiateDefer = opts.shouldInitiateDefer; @@ -805,8 +805,8 @@ export class StreamItemsRecord { errors: Array; streamRecord: StreamRecord; path: ReadonlyArray; + priority: number; deferPriority: number; - streamPriority: number; items: Array; children: Set; isFinalRecord?: boolean; @@ -820,13 +820,13 @@ export class StreamItemsRecord { constructor(opts: { streamRecord: StreamRecord; path: Path | undefined; + priority: number; deferPriority: number; - streamPriority: number; }) { this.streamRecord = opts.streamRecord; this.path = pathToArray(opts.path); + this.priority = opts.priority; this.deferPriority = opts.deferPriority; - this.streamPriority = opts.streamPriority; this.children = new Set(); this.errors = []; this.isCompleted = false; diff --git a/src/execution/__tests__/defer-test.ts b/src/execution/__tests__/defer-test.ts index 7e1cf596f42..3073d152eb0 100644 --- a/src/execution/__tests__/defer-test.ts +++ b/src/execution/__tests__/defer-test.ts @@ -290,7 +290,7 @@ describe('Execute: defer directive', () => { assert(fieldDetails !== undefined); expect(fieldDetails[0].node).to.equal(field); - expect(fieldDetails[0].target?.priority).to.equal(1); + expect(fieldDetails[0].target?.deferPriority).to.equal(1); expect(deferPriority).to.equal(1); expect(isPromise(published)).to.equal(true); expect(resumed).to.equal(true); @@ -352,7 +352,7 @@ describe('Execute: defer directive', () => { expect(fieldDetails[0].node).to.equal(node1); expect(fieldDetails[0].target).to.equal(undefined); expect(fieldDetails[1].node).to.equal(node2); - expect(fieldDetails[1].target?.priority).to.equal(1); + expect(fieldDetails[1].target?.deferPriority).to.equal(1); expect(deferPriority).to.equal(0); expect(published).to.equal(true); }); diff --git a/src/execution/__tests__/executor-test.ts b/src/execution/__tests__/executor-test.ts index e79cf028e51..9132ca36bd7 100644 --- a/src/execution/__tests__/executor-test.ts +++ b/src/execution/__tests__/executor-test.ts @@ -223,8 +223,8 @@ describe('Execute: Handles basic execution tasks', () => { 'rootValue', 'operation', 'variableValues', + 'priority', 'deferPriority', - 'streamPriority', 'published', ); @@ -238,8 +238,8 @@ describe('Execute: Handles basic execution tasks', () => { schema, rootValue, operation, + priority: 0, deferPriority: 0, - streamPriority: 0, published: true, }); diff --git a/src/execution/collectFields.ts b/src/execution/collectFields.ts index dc2dd4be2c9..dc63ff803e1 100644 --- a/src/execution/collectFields.ts +++ b/src/execution/collectFields.ts @@ -211,14 +211,14 @@ function collectFieldsImpl( target = { ...defer, ancestors: [parentTarget], - priority: 1, + deferPriority: 1, }; newDeferUsages.push(target); } else { target = { ...defer, ancestors: [parentTarget, ...parentTarget.ancestors], - priority: parentTarget.priority + 1, + deferPriority: parentTarget.deferPriority + 1, }; newDeferUsages.push(target); } @@ -260,14 +260,14 @@ function collectFieldsImpl( target = { ...defer, ancestors: [parentTarget], - priority: 1, + deferPriority: 1, }; newDeferUsages.push(target); } else { target = { ...defer, ancestors: [parentTarget, ...parentTarget.ancestors], - priority: parentTarget.priority + 1, + deferPriority: parentTarget.deferPriority + 1, }; newDeferUsages.push(target); } diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 1fa6199c4a2..dc6becc9135 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -709,8 +709,8 @@ export function buildResolveInfo( rootValue: exeContext.rootValue, operation: exeContext.operation, variableValues: exeContext.variableValues, + priority: 0, deferPriority: 0, - streamPriority: 0, published: true, }; } @@ -726,8 +726,8 @@ export function buildResolveInfo( rootValue: exeContext.rootValue, operation: exeContext.operation, variableValues: exeContext.variableValues, + priority: incrementalDataRecord.priority, deferPriority: incrementalDataRecord.deferPriority, - streamPriority: incrementalDataRecord.streamPriority, published: incrementalDataRecord.published === true ? true @@ -1511,14 +1511,23 @@ function addNewDeferredGroupedFieldSets( newGroupedFieldSetDeferUsages, deferMap, ); - const deferredGroupedFieldSetRecord = new DeferredGroupedFieldSetRecord({ - path, - deferPriority: incrementalDataRecord.deferPriority + 1, - streamPriority: incrementalDataRecord.streamPriority, - deferredFragmentRecords, - groupedFieldSet, - shouldInitiateDefer, - }); + const deferredGroupedFieldSetRecord = shouldInitiateDefer + ? new DeferredGroupedFieldSetRecord({ + path, + priority: incrementalDataRecord.priority + 1, + deferPriority: incrementalDataRecord.deferPriority + 1, + deferredFragmentRecords, + groupedFieldSet, + shouldInitiateDefer: true, + }) + : new DeferredGroupedFieldSetRecord({ + path, + priority: incrementalDataRecord.priority, + deferPriority: incrementalDataRecord.deferPriority, + deferredFragmentRecords, + groupedFieldSet, + shouldInitiateDefer: false, + }); incrementalPublisher.reportNewDeferredGroupedFieldSetRecord( deferredGroupedFieldSetRecord, ); @@ -1982,8 +1991,8 @@ function executeStreamField( const streamItemsRecord = new StreamItemsRecord({ streamRecord, path: itemPath, + priority: incrementalDataRecord.priority + 1, deferPriority: 0, - streamPriority: incrementalDataRecord.streamPriority + 1, }); incrementalPublisher.reportNewStreamItemsRecord( streamItemsRecord, @@ -2176,8 +2185,8 @@ async function executeStreamAsyncIterator( const streamItemsRecord = new StreamItemsRecord({ streamRecord, path: itemPath, + priority: incrementalDataRecord.priority + 1, deferPriority: 0, - streamPriority: incrementalDataRecord.streamPriority + 1, }); incrementalPublisher.reportNewStreamItemsRecord( streamItemsRecord, diff --git a/src/type/definition.ts b/src/type/definition.ts index 2d212d9f46e..1da73124eb7 100644 --- a/src/type/definition.ts +++ b/src/type/definition.ts @@ -888,7 +888,7 @@ export type GraphQLFieldResolver< export interface DeferUsage { label: string | undefined; ancestors: ReadonlyArray; - priority: number; + deferPriority: number; } export type Target = DeferUsage | undefined; @@ -909,8 +909,8 @@ export interface GraphQLResolveInfo { readonly rootValue: unknown; readonly operation: OperationDefinitionNode; readonly variableValues: { [variable: string]: unknown }; + readonly priority: number; readonly deferPriority: number; - readonly streamPriority: number; readonly published: true | Promise; }