Skip to content

Commit

Permalink
remove completePromisedListItemValue
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Apr 21, 2024
1 parent e31d311 commit 56c16b1
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 @@ -1134,27 +1134,9 @@ async function completeAsyncIteratorValue(
break;
}

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,
iteration.value,
completedResults,
exeContext,
itemType,
Expand Down Expand Up @@ -1248,24 +1230,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 @@ -1389,21 +1354,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 @@ -1472,21 +1423,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 @@ -1525,6 +1462,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 @@ -1571,45 +1524,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 56c16b1

Please sign in to comment.