Skip to content

Commit

Permalink
perf: introduce completePromisedListItemValue
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Apr 8, 2024
1 parent 5a03a02 commit d171b67
Showing 1 changed file with 49 additions and 12 deletions.
61 changes: 49 additions & 12 deletions src/execution/execute.ts
Expand Up @@ -1108,19 +1108,17 @@ async function completeAsyncIteratorValue(
/* c8 ignore start */
if (isPromise(item)) {
completedResults.push(
completePromisedValue(
completePromisedListItemValue(
item,
acc,
exeContext,
itemType,
fieldGroup,
info,
itemPath,
item,
incrementalContext,
deferMap,
).then((resolved) => {
appendNewIncrementalDataRecords(acc, resolved[1]);
return resolved[0];
}),
),
);
containsPromise = true;
} else if (
Expand Down Expand Up @@ -1237,19 +1235,17 @@ function completeListValue(

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

async function completePromisedListItemValue(
item: unknown,
parent: GraphQLResult<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;
}
appendNewIncrementalDataRecords(parent, completed[1]);
return completed[0];
} 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 d171b67

Please sign in to comment.