Skip to content

Commit

Permalink
perf: introduce completePromisedListItemValue (#4051)
Browse files Browse the repository at this point in the history
depends on #4050
  • Loading branch information
yaacovCR authored Apr 24, 2024
1 parent 6d777e6 commit 6acf33f
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,19 +1107,17 @@ async function completeAsyncIteratorValue(
/* c8 ignore start */
if (isPromise(item)) {
completedResults.push(
completePromisedValue(
completePromisedListItemValue(
item,
graphqlWrappedResult,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
item,
incrementalContext,
deferMap,
).then((resolved) => {
graphqlWrappedResult[1].push(...resolved[1]);
return resolved[0];
}),
),
);
containsPromise = true;
} else if (
Expand Down Expand Up @@ -1232,19 +1230,17 @@ function completeListValue(

if (isPromise(item)) {
completedResults.push(
completePromisedValue(
completePromisedListItemValue(
item,
graphqlWrappedResult,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
item,
incrementalContext,
deferMap,
).then((resolved) => {
graphqlWrappedResult[1].push(...resolved[1]);
return resolved[0];
}),
),
);
containsPromise = true;
} else if (
Expand Down Expand Up @@ -1334,6 +1330,41 @@ function completeListItemValue(
return false;
}

async function completePromisedListItemValue(
item: unknown,
parent: GraphQLWrappedResult<Array<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;
}
parent[1].push(...completed[1]);
return completed[0];
} catch (rawError) {
const errors = (incrementalContext ?? exeContext).errors;
handleFieldError(rawError, itemType, fieldGroup, itemPath, errors);
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 6acf33f

Please sign in to comment.