Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::resolveFieldValueOrErrorprotectedWC 1.0

Isolates the "ReturnOrAbrupt" behavior to not de-opt the resolveField function. Returns the result of resolveFn or the abrupt-return Error object.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

\Throwable|Promise|Mixed.

Usage

// protected - for code of main (parent) or child class
$result = $this->resolveFieldValueOrError( $fieldDef, $fieldNode, $resolveFn, $argsMapper, $rootValue, $info, $contextValue );
$fieldDef(FieldDefinition) (required)
.
$fieldNode(FieldNode) (required)
.
$resolveFn(callable) (required)
.
$argsMapper(callable) (required)
.
$rootValue(mixed) (required)
.
$info(ResolveInfo) (required)
.
$contextValue(mixed) (required)
.

ReferenceExecutor::resolveFieldValueOrError() code WC 10.9.1

protected function resolveFieldValueOrError(
    FieldDefinition $fieldDef,
    FieldNode $fieldNode,
    callable $resolveFn,
    callable $argsMapper,
    $rootValue,
    ResolveInfo $info,
    $contextValue
) {
    try {
        // Build a map of arguments from the field.arguments AST, using the
        // variables scope to fulfill any variable references.
        // @phpstan-ignore-next-line generics of SplObjectStorage are not inferred from empty instantiation
        $this->fieldArgsCache[$fieldDef] ??= new \SplObjectStorage();

        $args = $this->fieldArgsCache[$fieldDef][$fieldNode] ??= $argsMapper(Values::getArgumentValues(
            $fieldDef,
            $fieldNode,
            $this->exeContext->variableValues,
            $this->exeContext->schema,
        ), $fieldDef, $fieldNode, $contextValue);

        return $resolveFn($rootValue, $args, $contextValue, $info);
    } catch (\Throwable $error) {
        return $error;
    }
}