Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

ValuesOfCorrectType::isValidValueNodeprotectedWC 1.0

Method of the class: ValuesOfCorrectType{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->isValidValueNode( $context, $node ): void;
$context(QueryValidationContext) (required)
.
$node(VariableNode|NullValueNode|IntValueNode|FloatValueNode|StringValueNode|BooleanValueNode|EnumValueNode|ListValueNode|ObjectValueNode) (required)
.

ValuesOfCorrectType::isValidValueNode() code WC 10.9.1

protected function isValidValueNode(QueryValidationContext $context, ValueNode $node): void
{
    // Report any error at the full type expected by the location.
    $locationType = $context->getInputType();
    if ($locationType === null) {
        return;
    }

    $type = Type::getNamedType($locationType);

    if (! $type instanceof LeafType) {
        $typeStr = Utils::printSafe($type);
        $nodeStr = Printer::doPrint($node);
        $context->reportError(
            new Error(
                "Expected value of type \"{$typeStr}\", found {$nodeStr}.",
                $node
            )
        );

        return;
    }

    // Scalars determine if a literal value is valid via parseLiteral() which
    // may throw to indicate failure.
    try {
        $type->parseLiteral($node);
    } catch (\Throwable $error) {
        if ($error instanceof Error) {
            $context->reportError($error);
        } else {
            $typeStr = Utils::printSafe($type);
            $nodeStr = Printer::doPrint($node);
            $context->reportError(
                new Error(
                    "Expected value of type \"{$typeStr}\", found {$nodeStr}; {$error->getMessage()}",
                    $node,
                    null,
                    [],
                    null,
                    $error // Ensure a reference to the original error is maintained.
                )
            );
        }
    }
}