Skip to content

Commit

Permalink
deprecate streamPriority in favor of overall priority
Browse files Browse the repository at this point in the history
deferPriority is for use with lookahead to match what's included in the FieldDetails array

and overall priority is for... overall priority

deferPriority gets reset along with the field details for a deferred stream group when initiating a stream
  • Loading branch information
yaacovCR committed Jul 25, 2023
1 parent 1a4d602 commit 25ff375
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,23 @@ function isStreamItemsRecord(
export class InitialResultRecord {
errors: Array<GraphQLError>;
children: Set<SubsequentResultRecord>;
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;
}
}

/** @internal */
export class DeferredGroupedFieldSetRecord {
path: ReadonlyArray<string | number>;
priority: number;
deferPriority: number;
streamPriority: number;
deferredFragmentRecords: ReadonlyArray<DeferredFragmentRecord>;
groupedFieldSet: GroupedFieldSet;
shouldInitiateDefer: boolean;
Expand All @@ -733,15 +733,15 @@ export class DeferredGroupedFieldSetRecord {

constructor(opts: {
path: Path | undefined;
priority: number;
deferPriority: number;
streamPriority: number;
deferredFragmentRecords: ReadonlyArray<DeferredFragmentRecord>;
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;
Expand Down Expand Up @@ -805,8 +805,8 @@ export class StreamItemsRecord {
errors: Array<GraphQLError>;
streamRecord: StreamRecord;
path: ReadonlyArray<string | number>;
priority: number;
deferPriority: number;
streamPriority: number;
items: Array<unknown>;
children: Set<SubsequentResultRecord>;
isFinalRecord?: boolean;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ describe('Execute: Handles basic execution tasks', () => {
'rootValue',
'operation',
'variableValues',
'priority',
'deferPriority',
'streamPriority',
'published',
);

Expand All @@ -238,8 +238,8 @@ describe('Execute: Handles basic execution tasks', () => {
schema,
rootValue,
operation,
priority: 0,
deferPriority: 0,
streamPriority: 0,
published: true,
});

Expand Down
8 changes: 4 additions & 4 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
33 changes: 21 additions & 12 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,8 @@ export function buildResolveInfo(
rootValue: exeContext.rootValue,
operation: exeContext.operation,
variableValues: exeContext.variableValues,
priority: 0,
deferPriority: 0,
streamPriority: 0,
published: true,
};
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ export type GraphQLFieldResolver<
export interface DeferUsage {
label: string | undefined;
ancestors: ReadonlyArray<Target>;
priority: number;
deferPriority: number;
}

export type Target = DeferUsage | undefined;
Expand All @@ -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<void>;
}

Expand Down

0 comments on commit 25ff375

Please sign in to comment.