Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules

FieldsOnCorrectType::getVisitorpublicWC 1.0

Метод класса: FieldsOnCorrectType{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$FieldsOnCorrectType = new FieldsOnCorrectType();
$FieldsOnCorrectType->getVisitor( $context ): array;
$context(QueryValidationContext) (обязательный)
.

Код FieldsOnCorrectType::getVisitor() WC 10.9.1

public function getVisitor(QueryValidationContext $context): array
{
    return [
        NodeKind::FIELD => function (FieldNode $node) use ($context): void {
            $fieldDef = $context->getFieldDef();
            if ($fieldDef !== null && $fieldDef->isVisible()) {
                return;
            }

            $type = $context->getParentType();
            if (! $type instanceof NamedType) {
                return;
            }

            // This isn't valid. Let's find suggestions, if any.
            $schema = $context->getSchema();
            $fieldName = $node->name->value;
            // First determine if there are any suggested types to condition on.
            $suggestedTypeNames = $this->getSuggestedTypeNames($schema, $type, $fieldName);
            // If there are no suggested types, then perhaps this was a typo?
            $suggestedFieldNames = $suggestedTypeNames === []
                ? $this->getSuggestedFieldNames($type, $fieldName)
                : [];

            // Report an error, including helpful suggestions.
            $context->reportError(new Error(
                static::undefinedFieldMessage(
                    $node->name->value,
                    $type->name,
                    $suggestedTypeNames,
                    $suggestedFieldNames
                ),
                [$node]
            ));
        },
    ];
}