From af4ac88afa1a4920e3bc5d6e8b127205d6cee3e3 Mon Sep 17 00:00:00 2001 From: zephyx Date: Fri, 13 Dec 2024 17:49:00 +0100 Subject: [PATCH] ResolveInfo->getFieldSelectionWithAliases(): Fix edge case query with ListOf Type --- src/Type/Definition/ResolveInfo.php | 7 ++++--- tests/Type/ResolveInfoTest.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Type/Definition/ResolveInfo.php b/src/Type/Definition/ResolveInfo.php index fc8d1cf19..b8822e051 100644 --- a/src/Type/Definition/ResolveInfo.php +++ b/src/Type/Definition/ResolveInfo.php @@ -397,6 +397,10 @@ private function foldSelectionWithAlias(SelectionSetNode $selectionSet, int $des /** @var array $fields */ $fields = []; + if ($parentType instanceof WrappingType) { + $parentType = $parentType->getInnermostType(); + } + foreach ($selectionSet->selections as $selection) { if ($selection instanceof FieldNode) { $fieldName = $selection->name->value; @@ -410,9 +414,6 @@ private function foldSelectionWithAlias(SelectionSetNode $selectionSet, int $des $fieldDef = $parentType->getField($fieldName); $fieldType = $fieldDef->getType(); - if ($fieldType instanceof WrappingType) { - $fieldType = $fieldType->getInnermostType(); - } $fields[$fieldName][$aliasName]['args'] = Values::getArgumentValues($fieldDef, $selection, $this->variableValues); if ($descend <= 0) { diff --git a/tests/Type/ResolveInfoTest.php b/tests/Type/ResolveInfoTest.php index ca355bac4..193d45069 100644 --- a/tests/Type/ResolveInfoTest.php +++ b/tests/Type/ResolveInfoTest.php @@ -703,6 +703,21 @@ public function testGetFieldSelectionWithAliases(): void ], ]); + $queryList = new ObjectType([ + 'name' => 'Query', + 'fields' => [ + 'level1' => [ + 'type' => Type::listOf($level1), + 'resolve' => $returnResolveInfo, + 'args' => [ + 'testName' => [ + 'type' => Type::string(), + ], + ], + ], + ], + ]); + $result1 = GraphQL::executeQuery( new Schema(['query' => $query]), << $queryList]), + <<errors, 'Query NoAlias should have no errors'); self::assertEmpty($result2->errors, 'Query NoAliasFirst should have no errors'); self::assertEmpty($result3->errors, 'Query NoAliasLast should have no errors'); @@ -836,6 +863,7 @@ public function testGetFieldSelectionWithAliases(): void self::assertEmpty($result6->errors, 'Query WithFragments should have no errors'); self::assertSame('Failed asserting that two arrays are identical.', $result7->errors[0]->getMessage(), 'Query DeepestTooLowDepth should have failed'); self::assertEmpty($result8->errors, 'Query Deepest should have no errors'); + self::assertEmpty($result9->errors, 'Query With ListOf type should have no errors'); } public function testPathAndUnaliasedPath(): void