|
62 | 62 | class SchemaValidationContext
|
63 | 63 | {
|
64 | 64 | /** @var array<int, Error> */
|
65 |
| - private $errors = []; |
| 65 | + private array $errors = []; |
66 | 66 |
|
67 |
| - /** @var Schema */ |
68 |
| - private $schema; |
| 67 | + private Schema $schema; |
69 | 68 |
|
70 |
| - /** @var InputObjectCircularRefs */ |
71 |
| - private $inputObjectCircularRefs; |
| 69 | + private InputObjectCircularRefs $inputObjectCircularRefs; |
72 | 70 |
|
73 | 71 | public function __construct(Schema $schema)
|
74 | 72 | {
|
@@ -381,8 +379,9 @@ public function validateTypes(): void
|
381 | 379 | */
|
382 | 380 | private function validateDirectivesAtLocation(NodeList $directives, string $location)
|
383 | 381 | {
|
384 |
| - $directivesNamed = []; |
385 |
| - $schema = $this->schema; |
| 382 | + /** @var array<string, array<int, DirectiveNode>> $potentiallyDuplicateDirectives */ |
| 383 | + $potentiallyDuplicateDirectives = []; |
| 384 | + $schema = $this->schema; |
386 | 385 | foreach ($directives as $directive) {
|
387 | 386 | $directiveName = $directive->name->value;
|
388 | 387 |
|
@@ -412,18 +411,22 @@ static function ($schemaLocation) use ($location): bool {
|
412 | 411 | );
|
413 | 412 | }
|
414 | 413 |
|
415 |
| - $existingNodes = $directivesNamed[$directiveName] ?? []; |
416 |
| - $existingNodes[] = $directive; |
417 |
| - $directivesNamed[$directiveName] = $existingNodes; |
| 414 | + if ($schemaDirective->isRepeatable) { |
| 415 | + continue; |
| 416 | + } |
| 417 | + |
| 418 | + $existingNodes = $potentiallyDuplicateDirectives[$directiveName] ?? []; |
| 419 | + $existingNodes[] = $directive; |
| 420 | + $potentiallyDuplicateDirectives[$directiveName] = $existingNodes; |
418 | 421 | }
|
419 | 422 |
|
420 |
| - foreach ($directivesNamed as $directiveName => $directiveList) { |
| 423 | + foreach ($potentiallyDuplicateDirectives as $directiveName => $directiveList) { |
421 | 424 | if (count($directiveList) <= 1) {
|
422 | 425 | continue;
|
423 | 426 | }
|
424 | 427 |
|
425 | 428 | $this->reportError(
|
426 |
| - sprintf('Directive @%s used twice at the same location.', $directiveName), |
| 429 | + sprintf('Non-repeatable directive @%s used more than once at the same location.', $directiveName), |
427 | 430 | $directiveList
|
428 | 431 | );
|
429 | 432 | }
|
|
0 commit comments