Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::completeValueCatchingErrorprotectedWC 1.0

This is a small wrapper around completeValue which detects and logs errors in the execution context.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

Array|Promise|\stdClass|null.

Usage

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

ReferenceExecutor::completeValueCatchingError() code WC 10.9.1

protected function completeValueCatchingError(
    Type $returnType,
    \ArrayObject $fieldNodes,
    ResolveInfo $info,
    array $path,
    array $unaliasedPath,
    $result,
    $contextValue
) {
    // Otherwise, error protection is applied, logging the error and resolving
    // a null value for this field if one is encountered.
    try {
        $promise = $this->getPromise($result);
        if ($promise !== null) {
            $completed = $promise->then(fn (&$resolved) => $this->completeValue($returnType, $fieldNodes, $info, $path, $unaliasedPath, $resolved, $contextValue));
        } else {
            $completed = $this->completeValue($returnType, $fieldNodes, $info, $path, $unaliasedPath, $result, $contextValue);
        }

        $promise = $this->getPromise($completed);
        if ($promise !== null) {
            return $promise->then(null, function ($error) use ($fieldNodes, $path, $unaliasedPath, $returnType): void {
                $this->handleFieldError($error, $fieldNodes, $path, $unaliasedPath, $returnType);
            });
        }

        return $completed;
    } catch (\Throwable $err) {
        $this->handleFieldError($err, $fieldNodes, $path, $unaliasedPath, $returnType);

        return null;
    }
}