diff --git a/composer.json b/composer.json index 206ebebb5..655ae0c07 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "nyholm/psr7": "^1.5", "phpbench/phpbench": "^1.2", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "1.12.12", - "phpstan/phpstan-phpunit": "1.4.1", + "phpstan/phpstan": "1.12.13", + "phpstan/phpstan-phpunit": "1.4.2", "phpstan/phpstan-strict-rules": "1.6.1", "phpunit/phpunit": "^9.5 || ^10.5.21 || ^11", "psr/http-message": "^1 || ^2", diff --git a/docs/class-reference.md b/docs/class-reference.md index 26922b7fc..63102a358 100644 --- a/docs/class-reference.md +++ b/docs/class-reference.md @@ -430,37 +430,35 @@ public $variableValues; ```php /** - * Helper method that returns names of all fields selected in query for - * $this->fieldName up to $depth levels. + * Returns names of all fields selected in query for `$this->fieldName` up to `$depth` levels. * * Example: - * query MyQuery{ * { * root { - * id, + * id * nested { - * nested1 - * nested2 { - * nested3 - * } + * nested1 + * nested2 { + * nested3 + * } * } * } * } * - * Given this ResolveInfo instance is a part of "root" field resolution, and $depth === 1, - * method will return: + * Given this ResolveInfo instance is a part of root field resolution, and $depth === 1, + * this method will return: * [ * 'id' => true, * 'nested' => [ - * nested1 => true, - * nested2 => true - * ] + * 'nested1' => true, + * 'nested2' => true, + * ], * ] * - * Warning: this method it is a naive implementation which does not take into account - * conditional typed fragments. So use it with care for fields of interface and union types. + * This method does not consider conditional typed fragments. + * Use it with care for fields of interface and union types. * - * @param int $depth How many levels to include in output + * @param int $depth How many levels to include in the output beyond the first * * @return array * @@ -469,6 +467,104 @@ public $variableValues; function getFieldSelection(int $depth = 0): array ``` +```php +/** + * Returns names and args of all fields selected in query for `$this->fieldName` up to `$depth` levels, including aliases. + * + * The result maps original field names to a map of selections for that field, including aliases. + * For each of those selections, you can find the following keys: + * - "args" contains the passed arguments for this field/alias + * - "selectionSet" contains potential nested fields of this field/alias. The structure is recursive from here. + * + * Example: + * { + * root { + * id + * nested { + * nested1(myArg: 1) + * nested1Bis: nested1 + * } + * alias1: nested { + * nested1(myArg: 2, mySecondAg: "test") + * } + * } + * } + * + * Given this ResolveInfo instance is a part of "root" field resolution, and $depth === 1, + * this method will return: + * [ + * 'id' => [ + * 'id' => [ + * 'args' => [], + * ], + * ], + * 'nested' => [ + * 'nested' => [ + * 'args' => [], + * 'selectionSet' => [ + * 'nested1' => [ + * 'nested1' => [ + * 'args' => [ + * 'myArg' => 1, + * ], + * ], + * 'nested1Bis' => [ + * 'args' => [], + * ], + * ], + * ], + * ], + * 'alias1' => [ + * 'args' => [], + * 'selectionSet' => [ + * 'nested1' => [ + * 'nested1' => [ + * 'args' => [ + * 'myArg' => 2, + * 'mySecondAg' => "test, + * ], + * ], + * ], + * ], + * ], + * ], + * ] + * + * This method does not consider conditional typed fragments. + * Use it with care for fields of interface and union types. + * You can still alias the union type fields with the same name in order to extract their corresponding args. + * + * Example: + * { + * root { + * id + * unionPerson { + * ...on Child { + * name + * birthdate(format: "d/m/Y") + * } + * ...on Adult { + * adultName: name + * adultBirthDate: birthdate(format: "Y-m-d") + * job + * } + * } + * } + * } + * + * @param int $depth How many levels to include in the output beyond the first + * + * @throws \Exception + * @throws Error + * @throws InvariantViolation + * + * @return array + * + * @api + */ +function getFieldSelectionWithAliases(int $depth = 0): array +``` + ## GraphQL\Language\DirectiveLocation Enumeration of available directive locations.