Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::completeListValueprotectedWC 1.0

Complete a list value by completing each item in the list with the inner type.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

Array|Promise|\stdClass.

Usage

// protected - for code of main (parent) or child class
$result = $this->completeListValue( $returnType, $fieldNodes, $info, $path, $unaliasedPath, $results, $contextValue );
$returnType(ListOfType<Type&OutputType>) (required)
.
$fieldNodes(ArrayObject) (required)
.
$info(ResolveInfo) (required)
.
$path(list<string|int>) (required)
.
$unaliasedPath(list<string|int>) (required)
.
$results(iterable) (required)
.
$contextValue(mixed) (required)
.

ReferenceExecutor::completeListValue() code WC 10.9.1

protected function completeListValue(
    ListOfType $returnType,
    \ArrayObject $fieldNodes,
    ResolveInfo $info,
    array $path,
    array $unaliasedPath,
    iterable $results,
    $contextValue
) {
    $itemType = $returnType->getWrappedType();

    $i = 0;
    $containsPromise = false;
    $completedItems = [];
    foreach ($results as $item) {
        $itemPath = [...$path, $i];
        $info->path = $itemPath;
        $itemUnaliasedPath = [...$unaliasedPath, $i];
        $info->unaliasedPath = $itemUnaliasedPath;
        ++$i;

        $completedItem = $this->completeValueCatchingError($itemType, $fieldNodes, $info, $itemPath, $itemUnaliasedPath, $item, $contextValue);

        if (! $containsPromise && $this->getPromise($completedItem) !== null) {
            $containsPromise = true;
        }

        $completedItems[] = $completedItem;
    }

    return $containsPromise
        ? $this->exeContext->promiseAdapter->all($completedItems)
        : $completedItems;
}