Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

@@ -1,19 +1,19 @@
<?php
declare(strict_types=1);
namespace GraphQL\Validator\Rules;
use GraphQL\Error\Error;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\NameNode;
use GraphQL\Language\AST\NodeKind;
use GraphQL\Language\AST\VariableDefinitionNode;
use GraphQL\Validator\ValidationContext;
use function sprintf;
class UniqueVariableNames extends AbstractValidationRule
class UniqueVariableNames extends ValidationRule
{
static function duplicateVariableMessage($variableName)
{
return "There can be only one variable named \"$variableName\".";
}
/** @var NameNode[] */
public $knownVariableNames;
public function getVisitor(ValidationContext $context)
@@ -21,20 +21,25 @@ class UniqueVariableNames extends AbstractValidationRule
$this->knownVariableNames = [];
return [
NodeKind::OPERATION_DEFINITION => function() {
NodeKind::OPERATION_DEFINITION => function () : void {
$this->knownVariableNames = [];
},
NodeKind::VARIABLE_DEFINITION => function(VariableDefinitionNode $node) use ($context) {
NodeKind::VARIABLE_DEFINITION => function (VariableDefinitionNode $node) use ($context) : void {
$variableName = $node->variable->name->value;
if (!empty($this->knownVariableNames[$variableName])) {
if (! isset($this->knownVariableNames[$variableName])) {
$this->knownVariableNames[$variableName] = $node->variable->name;
} else {
$context->reportError(new Error(
self::duplicateVariableMessage($variableName),
[ $this->knownVariableNames[$variableName], $node->variable->name ]
[$this->knownVariableNames[$variableName], $node->variable->name]
));
} else {
$this->knownVariableNames[$variableName] = $node->variable->name;
}
}
},
];
}
public static function duplicateVariableMessage($variableName)
{
return sprintf('There can be only one variable named "%s".', $variableName);
}
}