Skip to content

Commit

Permalink
ResolveInfo->getFieldSelectionWithAliases(): Fix edge case query with…
Browse files Browse the repository at this point in the history
… ListOf Type
  • Loading branch information
zephyx authored and spawnia committed Dec 19, 2024
1 parent 5203bf2 commit af4ac88
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Type/Definition/ResolveInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ private function foldSelectionWithAlias(SelectionSetNode $selectionSet, int $des
/** @var array<string, bool> $fields */
$fields = [];

if ($parentType instanceof WrappingType) {
$parentType = $parentType->getInnermostType();
}

foreach ($selectionSet->selections as $selection) {
if ($selection instanceof FieldNode) {
$fieldName = $selection->name->value;
Expand All @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions tests/Type/ResolveInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
<<<GRAPHQL
Expand Down Expand Up @@ -828,6 +843,18 @@ public function testGetFieldSelectionWithAliases(): void
GRAPHQL
);

$result9 = GraphQL::executeQuery(
new Schema(['query' => $queryList]),
<<<GRAPHQL
query {
level1(testName: "NoAliasFirst") {
level2(width: 1, height: 1)
level1000: level2(width: 2, height: 20)
}
}
GRAPHQL
);

self::assertEmpty($result1->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');
Expand All @@ -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
Expand Down

0 comments on commit af4ac88

Please sign in to comment.