Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/execution/__tests__/stream-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,6 @@ describe('Execute: stream directive', () => {
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ name: 'Leia', id: '3' }],
path: ['friendList', 2],
Expand Down Expand Up @@ -984,11 +979,6 @@ describe('Execute: stream directive', () => {
},
],
},
],
hasNext: true,
},
{
incremental: [
{
items: [{ nonNullName: 'Han' }],
path: ['friendList', 2],
Expand Down
50 changes: 25 additions & 25 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1791,16 +1791,21 @@ function executeDeferredFragment(
fields,
asyncPayloadRecord,
);

if (isPromise(promiseOrData)) {
promiseOrData = promiseOrData.then(null, (e) => {
asyncPayloadRecord.errors.push(e);
return null;
});
}
} catch (e) {
asyncPayloadRecord.errors.push(e);
promiseOrData = null;
asyncPayloadRecord.addData(null);
return;
}

if (isPromise(promiseOrData)) {
promiseOrData.then(
(value) => asyncPayloadRecord.addData(value),
(error) => {
asyncPayloadRecord.errors.push(error);
asyncPayloadRecord.addData(null);
},
);
return;
}
asyncPayloadRecord.addData(promiseOrData);
}
Expand All @@ -1823,7 +1828,7 @@ function executeStreamField(
exeContext,
});
if (isPromise(item)) {
const completedItems = completePromisedValue(
completePromisedValue(
exeContext,
itemType,
fieldNodes,
Expand All @@ -1832,15 +1837,14 @@ function executeStreamField(
item,
asyncPayloadRecord,
).then(
(value) => [value],
(value) => asyncPayloadRecord.addItems([value]),
(error) => {
asyncPayloadRecord.errors.push(error);
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
return null;
asyncPayloadRecord.addItems(null);
},
);

asyncPayloadRecord.addItems(completedItems);
return asyncPayloadRecord;
}

Expand Down Expand Up @@ -1873,7 +1877,7 @@ function executeStreamField(
}

if (isPromise(completedItem)) {
const completedItems = completedItem
completedItem
.then(undefined, (rawError) => {
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
const handledError = handleFieldError(
Expand All @@ -1885,15 +1889,14 @@ function executeStreamField(
return handledError;
})
.then(
(value) => [value],
(value) => asyncPayloadRecord.addItems([value]),
(error) => {
asyncPayloadRecord.errors.push(error);
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
return null;
asyncPayloadRecord.addItems(null);
},
);

asyncPayloadRecord.addItems(completedItems);
return asyncPayloadRecord;
}

Expand Down Expand Up @@ -2008,22 +2011,19 @@ async function executeStreamIterator(

const { done, value: completedItem } = iteration;

let completedItems: PromiseOrValue<Array<unknown> | null>;
if (isPromise(completedItem)) {
completedItems = completedItem.then(
(value) => [value],
completedItem.then(
(resolvedItem) => asyncPayloadRecord.addItems([resolvedItem]),
(error) => {
asyncPayloadRecord.errors.push(error);
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
return null;
asyncPayloadRecord.addItems(null);
},
);
} else {
completedItems = [completedItem];
asyncPayloadRecord.addItems([completedItem]);
}

asyncPayloadRecord.addItems(completedItems);

if (done) {
break;
}
Expand Down Expand Up @@ -2202,7 +2202,7 @@ class DeferredFragmentRecord {
});
}

addData(data: PromiseOrValue<ObjMap<unknown> | null>) {
addData(data: ObjMap<unknown> | null) {
const parentData = this.parentContext?.promise;
if (parentData) {
this._resolve?.(parentData.then(() => data));
Expand Down Expand Up @@ -2253,7 +2253,7 @@ class StreamRecord {
});
}

addItems(items: PromiseOrValue<Array<unknown> | null>) {
addItems(items: Array<unknown> | null) {
const parentData = this.parentContext?.promise;
if (parentData) {
this._resolve?.(parentData.then(() => items));
Expand Down