Automattic\WooCommerce\Vendor\GraphQL\Validator\Rules
KnownArgumentNames{}└─ ValidationRule
Known argument names.
A Automattic\WooCommerce\Vendor\GraphQL field is only valid if all supplied arguments are defined by that field.
No Hooks.
Usage
$KnownArgumentNames = new KnownArgumentNames(); // use class methods
Methods
- public getVisitor(QueryValidationContext $context)
- public static unknownArgMessage(string $argName, string $fieldName, string $typeName, array $suggestedArgs)
KnownArgumentNames{} KnownArgumentNames{} code WC 10.9.1
class KnownArgumentNames extends ValidationRule
{
/** @throws InvariantViolation */
public function getVisitor(QueryValidationContext $context): array
{
$knownArgumentNamesOnDirectives = new KnownArgumentNamesOnDirectives();
return $knownArgumentNamesOnDirectives->getVisitor($context) + [
NodeKind::ARGUMENT => static function (ArgumentNode $node) use ($context): void {
$argDef = $context->getArgument();
if ($argDef !== null) {
return;
}
$fieldDef = $context->getFieldDef();
if ($fieldDef === null) {
return;
}
$parentType = $context->getParentType();
if (! $parentType instanceof NamedType) {
return;
}
$context->reportError(new Error(
static::unknownArgMessage(
$node->name->value,
$fieldDef->name,
$parentType->name,
Utils::suggestionList(
$node->name->value,
array_map(
static fn (Argument $arg): string => $arg->name,
$fieldDef->args
)
)
),
[$node]
));
},
];
}
/** @param array<string> $suggestedArgs */
public static function unknownArgMessage(string $argName, string $fieldName, string $typeName, array $suggestedArgs): string
{
$message = "Unknown argument \"{$argName}\" on field \"{$fieldName}\" of type \"{$typeName}\".";
if ($suggestedArgs !== []) {
$suggestions = Utils::quotedOrList($suggestedArgs);
$message .= " Did you mean {$suggestions}?";
}
return $message;
}
}