Skip to content

Commit

Permalink
rename iterator to asyncIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed May 5, 2023
1 parent 9b03404 commit b8ddb91
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ async function completeAsyncIteratorValue(
fieldGroup: FieldGroup,
info: GraphQLResolveInfo,
path: Path,
iterator: AsyncIterator<unknown>,
asyncIterator: AsyncIterator<unknown>,
incrementalDataRecord: IncrementalDataRecord | undefined,
): Promise<ReadonlyArray<unknown>> {
const stream = getStreamValues(exeContext, fieldGroup, path);
Expand All @@ -1072,7 +1072,7 @@ async function completeAsyncIteratorValue(
// eslint-disable-next-line @typescript-eslint/no-floating-promises
executeStreamAsyncIterator(
index,
iterator,
asyncIterator,
exeContext,
fieldGroup,
info,
Expand All @@ -1088,7 +1088,7 @@ async function completeAsyncIteratorValue(
let iteration;
try {
// eslint-disable-next-line no-await-in-loop
iteration = await iterator.next();
iteration = await asyncIterator.next();
if (iteration.done) {
break;
}
Expand Down Expand Up @@ -1140,15 +1140,15 @@ function completeListValue(
const itemType = returnType.ofType;

if (isAsyncIterable(result)) {
const iterator = result[Symbol.asyncIterator]();
const asyncIterator = result[Symbol.asyncIterator]();

return completeAsyncIteratorValue(
exeContext,
itemType,
fieldGroup,
info,
path,
iterator,
asyncIterator,
incrementalDataRecord,
);
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ function executeStreamField(
}

async function executeStreamAsyncIteratorItem(
iterator: AsyncIterator<unknown>,
asyncIterator: AsyncIterator<unknown>,
exeContext: ExecutionContext,
fieldGroup: FieldGroup,
info: GraphQLResolveInfo,
Expand All @@ -1958,9 +1958,9 @@ async function executeStreamAsyncIteratorItem(
): Promise<IteratorResult<unknown>> {
let item;
try {
const { value, done } = await iterator.next();
const { value, done } = await asyncIterator.next();
if (done) {
incrementalDataRecord.setIsCompletedIterator();
incrementalDataRecord.setIsCompletedAsyncIterator();
return { done, value: undefined };
}
item = value;
Expand All @@ -1973,7 +1973,7 @@ async function executeStreamAsyncIteratorItem(
itemPath,
incrementalDataRecord,
);
// don't continue if iterator throws
// don't continue if async iterator throws
return { done: true, value: null };
}
let completedItem;
Expand Down Expand Up @@ -2019,7 +2019,7 @@ async function executeStreamAsyncIteratorItem(

async function executeStreamAsyncIterator(
initialIndex: number,
iterator: AsyncIterator<unknown>,
asyncIterator: AsyncIterator<unknown>,
exeContext: ExecutionContext,
fieldGroup: FieldGroup,
info: GraphQLResolveInfo,
Expand All @@ -2037,15 +2037,15 @@ async function executeStreamAsyncIterator(
label,
path: itemPath,
parentContext: previousIncrementalDataRecord,
iterator,
asyncIterator,
exeContext,
});

let iteration;
try {
// eslint-disable-next-line no-await-in-loop
iteration = await executeStreamAsyncIteratorItem(
iterator,
asyncIterator,
exeContext,
fieldGroup,
info,
Expand All @@ -2058,8 +2058,8 @@ async function executeStreamAsyncIterator(
filterSubsequentPayloads(exeContext, path, incrementalDataRecord);
incrementalDataRecord.addItems(null);
// entire stream has errored and bubbled upwards
if (iterator?.return) {
iterator.return().catch(() => {
if (asyncIterator?.return) {
asyncIterator.return().catch(() => {
// ignore errors
});
}
Expand Down Expand Up @@ -2112,9 +2112,9 @@ function filterSubsequentPayloads(
// incrementalDataRecord path points to nulled error field
if (
isStreamItemsRecord(incrementalDataRecord) &&
incrementalDataRecord.iterator?.return
incrementalDataRecord.asyncIterator?.return
) {
incrementalDataRecord.iterator.return().catch(() => {
incrementalDataRecord.asyncIterator.return().catch(() => {
// ignore error
});
}
Expand All @@ -2134,7 +2134,7 @@ function getCompletedIncrementalResults(
exeContext.subsequentResults.delete(incrementalDataRecord);
if (isStreamItemsRecord(incrementalDataRecord)) {
const items = incrementalDataRecord.items;
if (incrementalDataRecord.isCompletedIterator) {
if (incrementalDataRecord.isCompletedAsyncIterator) {
// async iterable resolver just finished but there may be pending payloads
continue;
}
Expand Down Expand Up @@ -2199,9 +2199,9 @@ function yieldSubsequentPayloads(
exeContext.subsequentResults.forEach((incrementalDataRecord) => {
if (
isStreamItemsRecord(incrementalDataRecord) &&
incrementalDataRecord.iterator?.return
incrementalDataRecord.asyncIterator?.return
) {
promises.push(incrementalDataRecord.iterator.return());
promises.push(incrementalDataRecord.asyncIterator.return());
}
});
return Promise.all(promises);
Expand Down Expand Up @@ -2283,15 +2283,15 @@ class StreamItemsRecord {
items: Array<unknown> | null;
promise: Promise<void>;
parentContext: IncrementalDataRecord | undefined;
iterator: AsyncIterator<unknown> | undefined;
isCompletedIterator?: boolean;
asyncIterator: AsyncIterator<unknown> | undefined;
isCompletedAsyncIterator?: boolean;
isCompleted: boolean;
_exeContext: ExecutionContext;
_resolve?: (arg: PromiseOrValue<Array<unknown> | null>) => void;
constructor(opts: {
label: string | undefined;
path: Path | undefined;
iterator?: AsyncIterator<unknown>;
asyncIterator?: AsyncIterator<unknown>;
parentContext: IncrementalDataRecord | undefined;
exeContext: ExecutionContext;
}) {
Expand All @@ -2300,7 +2300,7 @@ class StreamItemsRecord {
this.label = opts.label;
this.path = pathToArray(opts.path);
this.parentContext = opts.parentContext;
this.iterator = opts.iterator;
this.asyncIterator = opts.asyncIterator;
this.errors = [];
this._exeContext = opts.exeContext;
this._exeContext.subsequentResults.add(this);
Expand All @@ -2325,8 +2325,8 @@ class StreamItemsRecord {
this._resolve?.(items);
}

setIsCompletedIterator() {
this.isCompletedIterator = true;
setIsCompletedAsyncIterator() {
this.isCompletedAsyncIterator = true;
}
}

Expand Down

0 comments on commit b8ddb91

Please sign in to comment.