Skip to content

Commit 6070542

Browse files
authored
Fix validation of modified sparse ASTs (#1106)
1 parent 81b5c6b commit 6070542

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

.github/workflows/ci-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ jobs:
2424
- uses: actions/checkout@v2
2525

2626
- name: Install PHP
27-
uses: shivammathur/setup-php@2.9.0
27+
uses: shivammathur/setup-php@2.18.1
2828
with:
2929
php-version: ${{ matrix.php }}
3030
coverage: none
3131
extensions: json, mbstring
32+
3233
- name: Get Composer Cache Directory
3334
id: composer-cache
3435
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
#### Unreleased
44

5+
#### 14.11.6
6+
7+
Fixed:
8+
- Fix validation of modified sparse ASTs
9+
510
#### 14.11.5
611

712
Fixed:

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"sort-packages": true,
3838
"allow-plugins": {
3939
"dealerdirect/phpcodesniffer-composer-installer": true,
40-
"phpstan/extension-installer": true
40+
"phpstan/extension-installer": true,
41+
"ergebnis/composer-normalize": true
4142
}
4243
},
4344
"autoload": {

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,6 @@ parameters:
580580
count: 1
581581
path: src/Validator/ValidationContext.php
582582

583-
-
584-
message: "#^Only booleans are allowed in an if condition, GraphQL\\\\Language\\\\AST\\\\SelectionSetNode\\|null given\\.$#"
585-
count: 1
586-
path: src/Validator/ValidationContext.php
587-
588583
-
589584
message: "#^Only booleans are allowed in a negated boolean, array\\<GraphQL\\\\Language\\\\AST\\\\FragmentDefinitionNode\\> given\\.$#"
590585
count: 1

src/Validator/ValidationContext.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use SplObjectStorage;
3232
use function array_merge;
3333
use function array_pop;
34+
use function assert;
3435
use function count;
3536

3637
/**
@@ -180,16 +181,15 @@ public function getFragmentSpreads(HasSelectionSet $node) : array
180181
while (count($setsToVisit) > 0) {
181182
$set = array_pop($setsToVisit);
182183

183-
for ($i = 0, $selectionCount = count($set->selections); $i < $selectionCount; $i++) {
184-
$selection = $set->selections[$i];
184+
foreach ($set->selections as $selection) {
185185
if ($selection instanceof FragmentSpreadNode) {
186186
$spreads[] = $selection;
187-
} elseif ($selection instanceof FieldNode || $selection instanceof InlineFragmentNode) {
188-
if ($selection->selectionSet) {
189-
$setsToVisit[] = $selection->selectionSet;
190-
}
191187
} else {
192-
throw InvariantViolation::shouldNotHappen();
188+
assert($selection instanceof FieldNode || $selection instanceof InlineFragmentNode);
189+
$selectionSet = $selection->selectionSet;
190+
if ($selectionSet !== null) {
191+
$setsToVisit[] = $selectionSet;
192+
}
193193
}
194194
}
195195
}

0 commit comments

Comments
 (0)