Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules
FieldsOnCorrectType::getVisitor
Method of the class: FieldsOnCorrectType{}
No Hooks.
Returns
null. Nothing (null).
Usage
$FieldsOnCorrectType = new FieldsOnCorrectType(); $FieldsOnCorrectType->getVisitor( $context ): array;
- $context(QueryValidationContext) (required)
- .
FieldsOnCorrectType::getVisitor() FieldsOnCorrectType::getVisitor code 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]
));
},
];
}