diff --git a/src/Type/Definition/ResolveInfo.php b/src/Type/Definition/ResolveInfo.php index 0a4c52aa7..7b21d9098 100644 --- a/src/Type/Definition/ResolveInfo.php +++ b/src/Type/Definition/ResolveInfo.php @@ -219,7 +219,7 @@ public function getFieldSelection(int $depth = 0): array /** * Returns names of all fields selected in query for `$this->fieldName` up to `$depth` levels. * - * For each field there is a key "aliases" that lists all aliases of this field, + * For each field we create an array containing all aliases of this field, * or the original field name if a field is not aliased. * * For each of those aliases, you can find the following keys: @@ -244,48 +244,40 @@ public function getFieldSelection(int $depth = 0): array * this method will return: * [ * 'id' => [ - * 'aliases' => [ - * 'id' => [ - * 'args' => [] - * ] + * 'id' => [ + * 'args' => [] * ] * ], * 'nested' => [ - * 'aliases' => [ - * 'nested' => [ - * 'args' => [], - * 'fields' => [ + * 'nested' => [ + * 'args' => [], + * 'fields' => [ + * 'nested1' => [ * 'nested1' => [ - * 'aliases' => [ - * 'nested1' => [ - * 'args' => [ - * 'myArg' => 1 - * ] - * ], - * 'nested1Bis' => [ - * 'args' => [] - * ] - * ] - * ] + * 'args' => [ + * 'myArg' => 1 + * ] + * ], + * 'nested1Bis' => [ + * 'args' => [] + * ] * ] - * ], - * 'alias1' => [ - * 'args' => [], - * 'fields' => [ + * ] + * ], + * 'alias1' => [ + * 'args' => [], + * 'fields' => [ + * 'nested1' => [ * 'nested1' => [ - * 'aliases' => [ - * 'nested1' => [ - * 'args' => [ - * 'myArg' => 2, - * 'mySecondAg' => "test" - * ] - * ] - * ] + * 'args' => [ + * 'myArg' => 2, + * 'mySecondAg' => "test" + * ] * ] * ] * ] - * ] - * ] + * ] + * ] * ] * * Warning: this method it is a naive implementation which does not take into account @@ -419,10 +411,10 @@ private function foldSelectionWithAlias(SelectionSetNode $selectionSet, int $des if ($fieldType instanceof WrappingType) { $fieldType = $fieldType->getInnermostType(); } - $fields[$fieldName]['aliases'][$aliasName]['args'] = Values::getArgumentValues($fieldDef, $selectionNode, $this->variableValues); + $fields[$fieldName][$aliasName]['args'] = Values::getArgumentValues($fieldDef, $selectionNode, $this->variableValues); if ($descend > 0 && $selectionNode->selectionSet !== null) { - $fields[$fieldName]['aliases'][$aliasName]['fields'] = $this->foldSelectionWithAlias($selectionNode->selectionSet, $descend - 1, $fieldType); + $fields[$fieldName][$aliasName]['fields'] = $this->foldSelectionWithAlias($selectionNode->selectionSet, $descend - 1, $fieldType); } } elseif ($selectionNode instanceof FragmentSpreadNode) { $spreadName = $selectionNode->name->value; diff --git a/tests/Type/ResolveInfoTest.php b/tests/Type/ResolveInfoTest.php index 7d453b56d..927548477 100644 --- a/tests/Type/ResolveInfoTest.php +++ b/tests/Type/ResolveInfoTest.php @@ -660,12 +660,10 @@ public function testFieldSelectionWithAlias(): void case 'NoAlias': self::assertSame([ 'level2' => [ - 'aliases' => [ - 'level2' => [ - 'args' => [ - 'width' => 1, - 'height' => 1, - ], + 'level2' => [ + 'args' => [ + 'width' => 1, + 'height' => 1, ], ], ], @@ -674,18 +672,16 @@ public function testFieldSelectionWithAlias(): void case 'NoAliasFirst': self::assertSame([ 'level2' => [ - 'aliases' => [ - 'level2' => [ - 'args' => [ - 'width' => 1, - 'height' => 1, - ], + 'level2' => [ + 'args' => [ + 'width' => 1, + 'height' => 1, ], - 'level1000' => [ - 'args' => [ - 'width' => 2, - 'height' => 20, - ], + ], + 'level1000' => [ + 'args' => [ + 'width' => 2, + 'height' => 20, ], ], ], @@ -694,18 +690,16 @@ public function testFieldSelectionWithAlias(): void case 'NoAliasLast': self::assertSame([ 'level2' => [ - 'aliases' => [ - 'level2000' => [ - 'args' => [ - 'width' => 1, - 'height' => 1, - ], + 'level2000' => [ + 'args' => [ + 'width' => 1, + 'height' => 1, ], - 'level2' => [ - 'args' => [ - 'width' => 2, - 'height' => 20, - ], + ], + 'level2' => [ + 'args' => [ + 'width' => 2, + 'height' => 20, ], ], ], @@ -714,18 +708,16 @@ public function testFieldSelectionWithAlias(): void case 'AllAliases': self::assertSame([ 'level2' => [ - 'aliases' => [ - 'level1000' => [ - 'args' => [ - 'width' => 1, - 'height' => 1, - ], + 'level1000' => [ + 'args' => [ + 'width' => 1, + 'height' => 1, ], - 'level2000' => [ - 'args' => [ - 'width' => 2, - 'height' => 20, - ], + ], + 'level2000' => [ + 'args' => [ + 'width' => 2, + 'height' => 20, ], ], ], @@ -735,38 +727,32 @@ public function testFieldSelectionWithAlias(): void case 'WithFragments': self::assertSame([ 'level2' => [ - 'aliases' => [ - 'level3000' => [ - 'args' => [ - 'width' => 1, - 'height' => 1, - ], + 'level3000' => [ + 'args' => [ + 'width' => 1, + 'height' => 1, ], - 'level2' => [ - 'args' => [ - 'width' => 3, - 'height' => 30, - ], + ], + 'level2' => [ + 'args' => [ + 'width' => 3, + 'height' => 30, ], ], ], 'level2bis' => [ - 'aliases' => [ - 'level2bis' => [ - 'args' => [], - 'fields' => [ + 'level2bis' => [ + 'args' => [], + 'fields' => [ + 'level3' => [ + 'level3000' => [ + 'args' => [ + 'length' => 2, + ], + ], 'level3' => [ - 'aliases' => [ - 'level3000' => [ - 'args' => [ - 'length' => 2, - ], - ], - 'level3' => [ - 'args' => [ - 'length' => 10, - ], - ], + 'args' => [ + 'length' => 10, ], ], ], @@ -783,49 +769,39 @@ public function testFieldSelectionWithAlias(): void $aliasArgs = $info->getFieldSelectionWithAlias($depth); self::assertSame([ 'level2bis' => [ - 'aliases' => [ - 'level2Alias' => [ - 'args' => [], - 'fields' => [ + 'level2Alias' => [ + 'args' => [], + 'fields' => [ + 'level3deeper' => [ 'level3deeper' => [ - 'aliases' => [ - 'level3deeper' => [ - 'args' => [], - 'fields' => [ - 'level4evenmore' => [ - 'aliases' => [ - 'level4evenmore' => [ - 'args' => [], - 'fields' => [ - 'level5' => [ - 'aliases' => [ - 'level5' => [ - 'args' => [ - 'crazyness' => 0.124, - ], - ], - 'lastAlias' => [ - 'args' => [ - 'crazyness' => 0.758, - ], - ], - ], - ], + 'args' => [], + 'fields' => [ + 'level4evenmore' => [ + 'level4evenmore' => [ + 'args' => [], + 'fields' => [ + 'level5' => [ + 'level5' => [ + 'args' => [ + 'crazyness' => 0.124, ], ], - ], - ], - 'level4' => [ - 'aliases' => [ - 'level4' => [ + 'lastAlias' => [ 'args' => [ - 'temperature' => -20, + 'crazyness' => 0.758, ], ], ], ], ], ], + 'level4' => [ + 'level4' => [ + 'args' => [ + 'temperature' => -20, + ], + ], + ], ], ], ],