Skip to content

Commit

Permalink
Merge branch 'master' into simplify-continue
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Validator/Rules/UniqueDirectivesPerLocation.php
  • Loading branch information
spawnia committed Jan 24, 2022
2 parents 5dbbf64 + 9faf59a commit e771009
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ You can find and compare releases at the [GitHub release page](https://github.co
- Allow directives on variable definitions
- Handle `null` parent of list in `ValuesOfCorrectType::getVisitor`
- Allow sending both `query` and `queryId`, ignore `queryId` in that case
- Fix `extend()` to preserve `repeatable` (#931)
- Preserve extended methods from class-based types in `SchemaExtender::extend()`
- Fix printing of empty types (#940)
- Clone `NodeList` in `Node::cloneDeep()`
Expand Down Expand Up @@ -105,6 +104,18 @@ You can find and compare releases at the [GitHub release page](https://github.co
- Remove parameter `$options` from `ASTDefinitionBuilder`
- Remove `FieldDefinition::create()` in favor of `new FieldDefinition()`

## 14.11.5

### Fixed

- Fix `extend()` to preserve `repeatable` (#931)

## 14.11.4

### Fixed

- Fix repeatable directive validation for AST

## 14.11.3

### Fixed
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dms/phpunit-arraysubset-asserts": "^0.3",
"doctrine/coding-standard": "^9",
"ergebnis/composer-normalize": "^2.16",
"friendsofphp/php-cs-fixer": "3.4.*",
"mll-lab/php-cs-fixer-config": "^4.4",
"nyholm/psr7": "^1.4",
"phpbench/phpbench": "^1.2",
Expand All @@ -43,9 +44,9 @@
},
"autoload-dev": {
"psr-4": {
"GraphQL\\Tests\\": "tests/",
"GraphQL\\Benchmarks\\": "benchmarks/",
"GraphQL\\Examples\\Blog\\": "examples/01-blog/Blog/"
"GraphQL\\Examples\\Blog\\": "examples/01-blog/Blog/",
"GraphQL\\Tests\\": "tests/"
}
},
"config": {
Expand Down
11 changes: 8 additions & 3 deletions src/Validator/Rules/UniqueDirectivesPerLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,25 @@ public function getSDLVisitor(SDLValidationContext $context): array
*/
public function getASTVisitor(ASTValidationContext $context): array
{
/** @var array<string, true> $uniqueDirectiveMap */
$uniqueDirectiveMap = [];

$schema = $context->getSchema();
$definedDirectives = null !== $schema
? $schema->getDirectives()
: Directive::getInternalDirectives();
foreach ($definedDirectives as $directive) {
$uniqueDirectiveMap[$directive->name] = ! $directive->isRepeatable;
if (! $directive->isRepeatable) {
$uniqueDirectiveMap[$directive->name] = true;
}
}

$astDefinitions = $context->getDocument()->definitions;
foreach ($astDefinitions as $definition) {
if ($definition instanceof DirectiveDefinitionNode) {
$uniqueDirectiveMap[$definition->name->value] = $definition->repeatable;
if ($definition instanceof DirectiveDefinitionNode
&& ! $definition->repeatable
) {
$uniqueDirectiveMap[$definition->name->value] = true;
}
}

Expand Down
11 changes: 8 additions & 3 deletions tests/Validator/ValidatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,20 @@ public static function getTestSchema(): Schema
Directive::deprecatedDirective(),
new Directive([
'name' => 'directive',
'locations' => [DirectiveLocation::FIELD],
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
]),
new Directive([
'name' => 'directiveA',
'locations' => [DirectiveLocation::FIELD],
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
]),
new Directive([
'name' => 'directiveB',
'locations' => [DirectiveLocation::FIELD],
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
]),
new Directive([
'name' => 'repeatable',
'locations' => [DirectiveLocation::FIELD, DirectiveLocation::FRAGMENT_DEFINITION],
'isRepeatable' => true,
]),
new Directive([
'name' => 'onQuery',
Expand Down

0 comments on commit e771009

Please sign in to comment.