Skip to content

Commit b12dcff

Browse files
authored
skip unnecessary initialization of empty items array (#3962)
We can use a non-null assertion to access `items ` on the completed StreamItemsRecord, similar to how `data` is accessed with a non-null assertion for completed DeferredGroupedFieldSet records, avoiding initialization of empty arrays/objects simply to avoid type errors.
1 parent d2e280a commit b12dcff

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/execution/IncrementalPublisher.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,9 @@ export class IncrementalPublisher {
565565
continue;
566566
}
567567
const incrementalResult: IncrementalStreamResult = {
568-
items: subsequentResultRecord.items,
568+
// safe because `items` is always defined when the record is completed
569+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
570+
items: subsequentResultRecord.items!,
569571
// safe because `id` is defined once the stream has been released as pending
570572
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
571573
id: subsequentResultRecord.streamRecord.id!,
@@ -624,6 +626,7 @@ export class IncrementalPublisher {
624626
);
625627
const id = recordWithLongestPath.id;
626628
const incrementalDeferResult: IncrementalDeferResult = {
629+
// safe because `data``is always defined when the record is completed
627630
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
628631
data: data!,
629632
// safe because `id` is defined once the fragment has been released as pending
@@ -825,7 +828,7 @@ export class StreamItemsRecord {
825828
errors: Array<GraphQLError>;
826829
streamRecord: StreamRecord;
827830
path: ReadonlyArray<string | number>;
828-
items: Array<unknown>;
831+
items: Array<unknown> | undefined;
829832
children: Set<SubsequentResultRecord>;
830833
isFinalRecord?: boolean;
831834
isCompletedAsyncIterator?: boolean;
@@ -839,7 +842,6 @@ export class StreamItemsRecord {
839842
this.errors = [];
840843
this.isCompleted = false;
841844
this.filtered = false;
842-
this.items = [];
843845
}
844846
}
845847

0 commit comments

Comments
 (0)