Skip to content

Commit

Permalink
allow nested defers at the same level
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Dec 22, 2023
1 parent 2aedf25 commit 79a69a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/execution/__tests__/defer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,28 +355,32 @@ describe('Execute: defer directive', () => {
data: {
hero: {},
},
pending: [
{ id: '0', path: ['hero'], label: 'DeferTop' },
{ id: '1', path: ['hero'], label: 'DeferNested' },
],
pending: [{ id: '0', path: ['hero'], label: 'DeferTop' }],
hasNext: true,
},
{
pending: [{ id: '1', path: ['hero'], label: 'DeferNested' }],
incremental: [
{
data: {
id: '1',
},
id: '0',
},
],
completed: [{ id: '0' }],
hasNext: true,
},
{
incremental: [
{
data: {
friends: [{ name: 'Han' }, { name: 'Leia' }, { name: 'C-3PO' }],
},
id: '1',
},
],
completed: [{ id: '0' }, { id: '1' }],
completed: [{ id: '1' }],
hasNext: false,
},
]);
Expand Down
9 changes: 3 additions & 6 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ function collectFieldsImpl(
context: CollectFieldsContext,
selectionSet: SelectionSetNode,
groupedFieldSet: AccumulatorMap<string, FieldDetails>,
parentDeferUsage?: DeferUsage,
deferUsage?: DeferUsage,
): void {
const {
Expand All @@ -143,7 +142,7 @@ function collectFieldsImpl(
}
groupedFieldSet.add(getFieldEntryKey(selection), {
node: selection,
deferUsage: deferUsage ?? parentDeferUsage,
deferUsage,
});
break;
}
Expand All @@ -159,14 +158,13 @@ function collectFieldsImpl(
operation,
variableValues,
selection,
parentDeferUsage,
deferUsage,
);

collectFieldsImpl(
context,
selection.selectionSet,
groupedFieldSet,
parentDeferUsage,
newDeferUsage ?? deferUsage,
);

Expand All @@ -179,7 +177,7 @@ function collectFieldsImpl(
operation,
variableValues,
selection,
parentDeferUsage,
deferUsage,
);

if (
Expand All @@ -205,7 +203,6 @@ function collectFieldsImpl(
context,
fragment.selectionSet,
groupedFieldSet,
parentDeferUsage,
newDeferUsage ?? deferUsage,
);
break;
Expand Down

0 comments on commit 79a69a5

Please sign in to comment.