Skip to content

Commit

Permalink
remove completePromisedListItemValue
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Apr 8, 2024
1 parent 25a0425 commit d996635
Showing 1 changed file with 21 additions and 107 deletions.
128 changes: 21 additions & 107 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,27 +1116,9 @@ async function completeAsyncIteratorValue(
break;
}

const item = iteration.value;
// TODO: add test case for asyncIterator returning a promise
/* c8 ignore start */
if (isPromise(item)) {
completedResults.push(
completePromisedListItemValue(
item,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
incrementalContext,
deferMap,
),
);
containsPromise = true;
} else if (
/* c8 ignore stop */
if (
completeListItemValue(
item,
iteration.value,
completedResults,
exeContext,
itemType,
Expand Down Expand Up @@ -1229,24 +1211,7 @@ async function completeAsyncIteratorValueWithPossibleStream(
}

const item = iteration.value;
// TODO: add tests for stream backed by asyncIterator that returns a promise
/* c8 ignore start */
if (isPromise(item)) {
completedResults.push(
completePromisedListItemValue(
item,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
incrementalContext,
deferMap,
),
);
containsPromise = true;
} else if (
/* c8 ignore stop */
if (
completeListItemValue(
item,
completedResults,
Expand Down Expand Up @@ -1370,21 +1335,7 @@ function completeIterableValue(
// since from here on it is not ever accessed by resolver functions.
const itemPath = addPath(path, index, undefined);

if (isPromise(item)) {
completedResults.push(
completePromisedListItemValue(
item,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
incrementalContext,
deferMap,
),
);
containsPromise = true;
} else if (
if (
completeListItemValue(
item,
completedResults,
Expand Down Expand Up @@ -1461,21 +1412,7 @@ function completeIterableValueWithPossibleStream(
// since from here on it is not ever accessed by resolver functions.
const itemPath = addPath(path, index, undefined);

if (isPromise(item)) {
completedResults.push(
completePromisedListItemValue(
item,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
incrementalContext,
deferMap,
),
);
containsPromise = true;
} else if (
if (
completeListItemValue(
item,
completedResults,
Expand Down Expand Up @@ -1515,6 +1452,22 @@ function completeListItemValue(
incrementalContext: IncrementalContext | undefined,
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
): boolean {
if (isPromise(item)) {
completedResults.push(
completePromisedValue(
exeContext,
itemType,
fieldGroup,
info,
itemPath,
item,
incrementalContext,
deferMap,
),
);
return true;
}

try {
const completedItem = completeValue(
exeContext,
Expand Down Expand Up @@ -1561,45 +1514,6 @@ function completeListItemValue(
return false;
}

async function completePromisedListItemValue(
item: unknown,
exeContext: ExecutionContext,
itemType: GraphQLOutputType,
fieldGroup: FieldGroup,
info: GraphQLResolveInfo,
itemPath: Path,
incrementalContext: IncrementalContext | undefined,
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
): Promise<unknown> {
try {
const resolved = await item;
let completed = completeValue(
exeContext,
itemType,
fieldGroup,
info,
itemPath,
resolved,
incrementalContext,
deferMap,
);
if (isPromise(completed)) {
completed = await completed;
}
return completed;
} catch (rawError) {
handleFieldError(
rawError,
exeContext,
itemType,
fieldGroup,
itemPath,
incrementalContext,
);
return null;
}
}

/**
* Complete a Scalar or Enum by serializing to a valid value, returning
* null if serialization is not possible.
Expand Down

0 comments on commit d996635

Please sign in to comment.