Skip to content

Commit af4ac88

Browse files
zephyxspawnia
authored andcommitted
ResolveInfo->getFieldSelectionWithAliases(): Fix edge case query with ListOf Type
1 parent 5203bf2 commit af4ac88

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Type/Definition/ResolveInfo.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ private function foldSelectionWithAlias(SelectionSetNode $selectionSet, int $des
397397
/** @var array<string, bool> $fields */
398398
$fields = [];
399399

400+
if ($parentType instanceof WrappingType) {
401+
$parentType = $parentType->getInnermostType();
402+
}
403+
400404
foreach ($selectionSet->selections as $selection) {
401405
if ($selection instanceof FieldNode) {
402406
$fieldName = $selection->name->value;
@@ -410,9 +414,6 @@ private function foldSelectionWithAlias(SelectionSetNode $selectionSet, int $des
410414

411415
$fieldDef = $parentType->getField($fieldName);
412416
$fieldType = $fieldDef->getType();
413-
if ($fieldType instanceof WrappingType) {
414-
$fieldType = $fieldType->getInnermostType();
415-
}
416417
$fields[$fieldName][$aliasName]['args'] = Values::getArgumentValues($fieldDef, $selection, $this->variableValues);
417418

418419
if ($descend <= 0) {

tests/Type/ResolveInfoTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,21 @@ public function testGetFieldSelectionWithAliases(): void
703703
],
704704
]);
705705

706+
$queryList = new ObjectType([
707+
'name' => 'Query',
708+
'fields' => [
709+
'level1' => [
710+
'type' => Type::listOf($level1),
711+
'resolve' => $returnResolveInfo,
712+
'args' => [
713+
'testName' => [
714+
'type' => Type::string(),
715+
],
716+
],
717+
],
718+
],
719+
]);
720+
706721
$result1 = GraphQL::executeQuery(
707722
new Schema(['query' => $query]),
708723
<<<GRAPHQL
@@ -828,6 +843,18 @@ public function testGetFieldSelectionWithAliases(): void
828843
GRAPHQL
829844
);
830845

846+
$result9 = GraphQL::executeQuery(
847+
new Schema(['query' => $queryList]),
848+
<<<GRAPHQL
849+
query {
850+
level1(testName: "NoAliasFirst") {
851+
level2(width: 1, height: 1)
852+
level1000: level2(width: 2, height: 20)
853+
}
854+
}
855+
GRAPHQL
856+
);
857+
831858
self::assertEmpty($result1->errors, 'Query NoAlias should have no errors');
832859
self::assertEmpty($result2->errors, 'Query NoAliasFirst should have no errors');
833860
self::assertEmpty($result3->errors, 'Query NoAliasLast should have no errors');
@@ -836,6 +863,7 @@ public function testGetFieldSelectionWithAliases(): void
836863
self::assertEmpty($result6->errors, 'Query WithFragments should have no errors');
837864
self::assertSame('Failed asserting that two arrays are identical.', $result7->errors[0]->getMessage(), 'Query DeepestTooLowDepth should have failed');
838865
self::assertEmpty($result8->errors, 'Query Deepest should have no errors');
866+
self::assertEmpty($result9->errors, 'Query With ListOf type should have no errors');
839867
}
840868

841869
public function testPathAndUnaliasedPath(): void

0 commit comments

Comments
 (0)