Skip to content

Commit

Permalink
add filtering again
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Apr 8, 2024
1 parent 8ff203d commit 25a0425
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 189 deletions.
23 changes: 12 additions & 11 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class IncrementalPublisher {
);
}

if (deferredGroupedFieldSetResult.incrementalDataRecords !== undefined) {
if (deferredGroupedFieldSetResult.incrementalDataRecords) {
this._addIncrementalDataRecords(
deferredGroupedFieldSetResult.incrementalDataRecords,
);
Expand Down Expand Up @@ -616,7 +616,7 @@ class IncrementalPublisher {

this._incremental.push(incrementalEntry);

if (streamItemsResult.incrementalDataRecords !== undefined) {
if (streamItemsResult.incrementalDataRecords) {
this._addIncrementalDataRecords(
streamItemsResult.incrementalDataRecords,
);
Expand Down Expand Up @@ -658,13 +658,13 @@ class IncrementalPublisher {
}
}

function isDeferredFragmentRecord(
export function isDeferredFragmentRecord(
subsequentResultRecord: SubsequentResultRecord,
): subsequentResultRecord is DeferredFragmentRecord {
return subsequentResultRecord instanceof DeferredFragmentRecord;
}

function isDeferredGroupedFieldSetRecord(
export function isDeferredGroupedFieldSetRecord(
incrementalDataRecord: IncrementalDataRecord,
): incrementalDataRecord is DeferredGroupedFieldSetRecord {
return incrementalDataRecord instanceof DeferredGroupedFieldSetRecord;
Expand All @@ -673,7 +673,8 @@ function isDeferredGroupedFieldSetRecord(
export interface IncrementalContext {
deferUsageSet: DeferUsageSet | undefined;
path: Path | undefined;
errors?: Array<GraphQLError> | undefined;
errors?: Map<Path | undefined, GraphQLError> | undefined;
incrementalDataRecords?: Array<IncrementalDataRecord> | undefined;
}

export type DeferredGroupedFieldSetResult =
Expand All @@ -690,7 +691,7 @@ interface ReconcilableDeferredGroupedFieldSetResult {
deferredFragmentRecords: ReadonlyArray<DeferredFragmentRecord>;
path: Array<string | number>;
result: BareDeferredGroupedFieldSetResult;
incrementalDataRecords: ReadonlyArray<IncrementalDataRecord> | undefined;
incrementalDataRecords?: ReadonlyArray<IncrementalDataRecord> | undefined;
sent?: true | undefined;
}

Expand Down Expand Up @@ -795,7 +796,7 @@ interface NonReconcilableStreamItemsResult {
interface NonTerminatingStreamItemsResult {
streamRecord: StreamRecord;
result: BareStreamItemsResult;
incrementalDataRecords: ReadonlyArray<IncrementalDataRecord> | undefined;
incrementalDataRecords?: ReadonlyArray<IncrementalDataRecord> | undefined;
}

interface TerminatingStreamItemsResult {
Expand Down Expand Up @@ -857,10 +858,10 @@ export class StreamItemsRecord {
this.nextStreamItems !== undefined
? {
...result,
incrementalDataRecords:
result.incrementalDataRecords === undefined
? [this.nextStreamItems]
: [this.nextStreamItems, ...result.incrementalDataRecords],
incrementalDataRecords: [
this.nextStreamItems,
...(result.incrementalDataRecords ?? []),
],
}
: result;
}
Expand Down
13 changes: 11 additions & 2 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2096,14 +2096,23 @@ describe('Execute: stream directive', () => {
id: '2',
},
],
completed: [{ id: '2' }, { id: '1' }],
hasNext: false,
completed: [{ id: '2' }],
hasNext: true,
},
done: false,
});

const result5 = await iterator.next();
expectJSON(result5).toDeepEqual({
value: {
completed: [{ id: '1' }],
hasNext: false,
},
done: false,
});

const result6 = await iterator.next();
expectJSON(result6).toDeepEqual({
value: undefined,
done: true,
});
Expand Down
Loading

0 comments on commit 25a0425

Please sign in to comment.