Skip to content

Commit

Permalink
skip unnecessary initialization of empty items array (#3962)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yaacovCR authored Aug 28, 2023
1 parent d2e280a commit b12dcff
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,9 @@ export class IncrementalPublisher {
continue;
}
const incrementalResult: IncrementalStreamResult = {
items: subsequentResultRecord.items,
// safe because `items` is always defined when the record is completed
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
items: subsequentResultRecord.items!,
// safe because `id` is defined once the stream has been released as pending
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: subsequentResultRecord.streamRecord.id!,
Expand Down Expand Up @@ -624,6 +626,7 @@ export class IncrementalPublisher {
);
const id = recordWithLongestPath.id;
const incrementalDeferResult: IncrementalDeferResult = {
// safe because `data``is always defined when the record is completed
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
data: data!,
// safe because `id` is defined once the fragment has been released as pending
Expand Down Expand Up @@ -825,7 +828,7 @@ export class StreamItemsRecord {
errors: Array<GraphQLError>;
streamRecord: StreamRecord;
path: ReadonlyArray<string | number>;
items: Array<unknown>;
items: Array<unknown> | undefined;
children: Set<SubsequentResultRecord>;
isFinalRecord?: boolean;
isCompletedAsyncIterator?: boolean;
Expand All @@ -839,7 +842,6 @@ export class StreamItemsRecord {
this.errors = [];
this.isCompleted = false;
this.filtered = false;
this.items = [];
}
}

Expand Down

0 comments on commit b12dcff

Please sign in to comment.