Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -1,36 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace GraphQL\Validator\Rules;
|
||||
|
||||
use GraphQL\Error\Error;
|
||||
use GraphQL\Language\AST\ArgumentNode;
|
||||
use GraphQL\Language\AST\Node;
|
||||
use GraphQL\Language\AST\NameNode;
|
||||
use GraphQL\Language\AST\NodeKind;
|
||||
use GraphQL\Language\Visitor;
|
||||
use GraphQL\Language\VisitorOperation;
|
||||
use GraphQL\Validator\ASTValidationContext;
|
||||
use GraphQL\Validator\SDLValidationContext;
|
||||
use GraphQL\Validator\ValidationContext;
|
||||
use function sprintf;
|
||||
|
||||
class UniqueArgumentNames extends AbstractValidationRule
|
||||
class UniqueArgumentNames extends ValidationRule
|
||||
{
|
||||
static function duplicateArgMessage($argName)
|
||||
{
|
||||
return "There can be only one argument named \"$argName\".";
|
||||
}
|
||||
|
||||
/** @var NameNode[] */
|
||||
public $knownArgNames;
|
||||
|
||||
public function getSDLVisitor(SDLValidationContext $context)
|
||||
{
|
||||
return $this->getASTVisitor($context);
|
||||
}
|
||||
|
||||
public function getVisitor(ValidationContext $context)
|
||||
{
|
||||
return $this->getASTVisitor($context);
|
||||
}
|
||||
|
||||
public function getASTVisitor(ASTValidationContext $context)
|
||||
{
|
||||
$this->knownArgNames = [];
|
||||
|
||||
return [
|
||||
NodeKind::FIELD => function () {
|
||||
$this->knownArgNames = [];;
|
||||
},
|
||||
NodeKind::DIRECTIVE => function () {
|
||||
NodeKind::FIELD => function () : void {
|
||||
$this->knownArgNames = [];
|
||||
},
|
||||
NodeKind::ARGUMENT => function (ArgumentNode $node) use ($context) {
|
||||
NodeKind::DIRECTIVE => function () : void {
|
||||
$this->knownArgNames = [];
|
||||
},
|
||||
NodeKind::ARGUMENT => function (ArgumentNode $node) use ($context) : VisitorOperation {
|
||||
$argName = $node->name->value;
|
||||
if (!empty($this->knownArgNames[$argName])) {
|
||||
if ($this->knownArgNames[$argName] ?? false) {
|
||||
$context->reportError(new Error(
|
||||
self::duplicateArgMessage($argName),
|
||||
[$this->knownArgNames[$argName], $node->name]
|
||||
@@ -38,8 +51,14 @@ class UniqueArgumentNames extends AbstractValidationRule
|
||||
} else {
|
||||
$this->knownArgNames[$argName] = $node->name;
|
||||
}
|
||||
|
||||
return Visitor::skipNode();
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public static function duplicateArgMessage($argName)
|
||||
{
|
||||
return sprintf('There can be only one argument named "%s".', $argName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user