Skip to content

Commit 6d634b4

Browse files
authored
Fix repeatable directive validation for AST (#1055)
1 parent 130ae95 commit 6d634b4

File tree

6 files changed

+30
-12
lines changed

6 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ You can find and compare releases at the [GitHub release page](https://github.co
104104
- Remove parameter `$options` from `ASTDefinitionBuilder`
105105
- Remove `FieldDefinition::create()` in favor of `new FieldDefinition()`
106106

107+
## 14.11.4
108+
109+
### Fixed
110+
111+
- Fix repeatable directive validation for AST
112+
107113
## 14.11.3
108114

109115
### Fixed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dms/phpunit-arraysubset-asserts": "^0.3",
1919
"doctrine/coding-standard": "^9",
2020
"ergebnis/composer-normalize": "^2.16",
21+
"friendsofphp/php-cs-fixer": "3.4.*",
2122
"mll-lab/php-cs-fixer-config": "^4.4",
2223
"nyholm/psr7": "^1.4",
2324
"phpbench/phpbench": "^1.2",

phpstan-baseline.neon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ parameters:
131131
path: src/Type/Definition/NonNull.php
132132

133133
-
134-
message: "#^Array \\(array\\<string, GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type\\>\\) does not accept GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
134+
message: "#^Generator expects value type GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Type\\\\Definition\\\\Type given\\.$#"
135135
count: 1
136136
path: src/Type/Schema.php
137137

138138
-
139-
message: "#^Generator expects value type GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type, GraphQL\\\\Type\\\\Definition\\\\Type given\\.$#"
139+
message: "#^Method GraphQL\\\\Type\\\\Schema\\:\\:getType\\(\\) should return \\(GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|null but returns GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
140140
count: 1
141141
path: src/Type/Schema.php
142142

143143
-
144-
message: "#^Method GraphQL\\\\Type\\\\Schema\\:\\:getType\\(\\) should return \\(GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|null but returns GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
144+
message: "#^Method GraphQL\\\\Type\\\\Schema\\:\\:resolveType\\(\\) should return T of GraphQL\\\\Type\\\\Definition\\\\Type but returns \\(callable&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|T of GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
145145
count: 1
146146
path: src/Type/Schema.php
147147

148148
-
149-
message: "#^Method GraphQL\\\\Type\\\\Schema\\:\\:resolveType\\(\\) should return T of GraphQL\\\\Type\\\\Definition\\\\Type but returns \\(callable&GraphQL\\\\Type\\\\Definition\\\\Type\\)\\|T of GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
149+
message: "#^Property GraphQL\\\\Type\\\\Schema\\:\\:\\$resolvedTypes \\(array\\<string, GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type\\>\\) does not accept array\\<string, GraphQL\\\\Type\\\\Definition\\\\Type\\>\\.$#"
150150
count: 1
151151
path: src/Type/Schema.php
152152

src/Utils/BuildClientSchema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public function buildSchema(): Schema
112112
}
113113

114114
$name = $typeIntrospection['name'];
115+
if (! is_string($name)) {
116+
throw self::invalidOrIncompleteIntrospectionResult($typeIntrospection);
117+
}
115118

116119
// Use the built-in singleton types to avoid reconstruction
117120
$this->typeMap[$name] = $builtInTypes[$name]

src/Validator/Rules/UniqueDirectivesPerLocation.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,26 @@ public function getSDLVisitor(SDLValidationContext $context): array
3636
*/
3737
public function getASTVisitor(ASTValidationContext $context): array
3838
{
39+
/** @var array<string, true> $uniqueDirectiveMap */
3940
$uniqueDirectiveMap = [];
4041

4142
$schema = $context->getSchema();
4243
$definedDirectives = null !== $schema
4344
? $schema->getDirectives()
4445
: Directive::getInternalDirectives();
4546
foreach ($definedDirectives as $directive) {
46-
$uniqueDirectiveMap[$directive->name] = ! $directive->isRepeatable;
47+
if (! $directive->isRepeatable) {
48+
$uniqueDirectiveMap[$directive->name] = true;
49+
}
4750
}
4851

4952
$astDefinitions = $context->getDocument()->definitions;
5053
foreach ($astDefinitions as $definition) {
51-
if (! ($definition instanceof DirectiveDefinitionNode)) {
52-
continue;
54+
if ($definition instanceof DirectiveDefinitionNode
55+
&& ! $definition->repeatable
56+
) {
57+
$uniqueDirectiveMap[$definition->name->value] = true;
5358
}
54-
55-
$uniqueDirectiveMap[$definition->name->value] = $definition->repeatable;
5659
}
5760

5861
return [

tests/Validator/ValidatorTestCase.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,20 @@ public static function getTestSchema(): Schema
373373
Directive::deprecatedDirective(),
374374
new Directive([
375375
'name' => 'directive',
376-
'locations' => [DirectiveLocation::FIELD],
376+
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
377377
]),
378378
new Directive([
379379
'name' => 'directiveA',
380-
'locations' => [DirectiveLocation::FIELD],
380+
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
381381
]),
382382
new Directive([
383383
'name' => 'directiveB',
384-
'locations' => [DirectiveLocation::FIELD],
384+
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
385+
]),
386+
new Directive([
387+
'name' => 'repeatable',
388+
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
389+
'isRepeatable' => true,
385390
]),
386391
new Directive([
387392
'name' => 'onQuery',

0 commit comments

Comments
 (0)