Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

ScalarLeafs::getVisitorpublicWC 1.0

Method of the class: ScalarLeafs{}

No Hooks.

Returns

null. Nothing (null).

Usage

$ScalarLeafs = new ScalarLeafs();
$ScalarLeafs->getVisitor( $context ): array;
$context(QueryValidationContext) (required)
.

ScalarLeafs::getVisitor() code WC 10.9.1

public function getVisitor(QueryValidationContext $context): array
{
    return [
        NodeKind::FIELD => static function (FieldNode $node) use ($context): void {
            $type = $context->getType();
            if ($type === null) {
                return;
            }

            if (Type::isLeafType(Type::getNamedType($type))) {
                if ($node->selectionSet !== null) {
                    $context->reportError(new Error(
                        static::noSubselectionAllowedMessage($node->name->value, $type->toString()),
                        [$node->selectionSet]
                    ));
                }
            } elseif ($node->selectionSet === null) {
                $context->reportError(new Error(
                    static::requiredSubselectionMessage($node->name->value, $type->toString()),
                    [$node]
                ));
            }
        },
    ];
}