@@ -430,37 +430,35 @@ public $variableValues;
430430
431431``` php
432432/**
433- * Helper method that returns names of all fields selected in query for
434- * $this->fieldName up to $depth levels.
433+ * Returns names of all fields selected in query for `$this->fieldName` up to `$depth` levels.
435434 *
436435 * Example:
437- * query MyQuery{
438436 * {
439437 * root {
440- * id,
438+ * id
441439 * nested {
442- * nested1
443- * nested2 {
444- * nested3
445- * }
440+ * nested1
441+ * nested2 {
442+ * nested3
443+ * }
446444 * }
447445 * }
448446 * }
449447 *
450- * Given this ResolveInfo instance is a part of " root" field resolution, and $depth === 1,
451- * method will return:
448+ * Given this ResolveInfo instance is a part of root field resolution, and $depth === 1,
449+ * this method will return:
452450 * [
453451 * 'id' => true,
454452 * 'nested' => [
455- * nested1 => true,
456- * nested2 => true
457- * ]
453+ * ' nested1' => true,
454+ * ' nested2' => true,
455+ * ],
458456 * ]
459457 *
460- * Warning: this method it is a naive implementation which does not take into account
461- * conditional typed fragments. So use it with care for fields of interface and union types.
458+ * This method does not consider conditional typed fragments.
459+ * Use it with care for fields of interface and union types.
462460 *
463- * @param int $depth How many levels to include in output
461+ * @param int $depth How many levels to include in the output beyond the first
464462 *
465463 * @return array<string , mixed >
466464 *
@@ -469,6 +467,104 @@ public $variableValues;
469467function getFieldSelection(int $depth = 0): array
470468```
471469
470+ ``` php
471+ /**
472+ * Returns names and args of all fields selected in query for `$this->fieldName` up to `$depth` levels, including aliases.
473+ *
474+ * The result maps original field names to a map of selections for that field, including aliases.
475+ * For each of those selections, you can find the following keys:
476+ * - "args" contains the passed arguments for this field/alias
477+ * - "selectionSet" contains potential nested fields of this field/alias. The structure is recursive from here.
478+ *
479+ * Example:
480+ * {
481+ * root {
482+ * id
483+ * nested {
484+ * nested1(myArg: 1)
485+ * nested1Bis: nested1
486+ * }
487+ * alias1: nested {
488+ * nested1(myArg: 2, mySecondAg: "test")
489+ * }
490+ * }
491+ * }
492+ *
493+ * Given this ResolveInfo instance is a part of "root" field resolution, and $depth === 1,
494+ * this method will return:
495+ * [
496+ * 'id' => [
497+ * 'id' => [
498+ * 'args' => [],
499+ * ],
500+ * ],
501+ * 'nested' => [
502+ * 'nested' => [
503+ * 'args' => [],
504+ * 'selectionSet' => [
505+ * 'nested1' => [
506+ * 'nested1' => [
507+ * 'args' => [
508+ * 'myArg' => 1,
509+ * ],
510+ * ],
511+ * 'nested1Bis' => [
512+ * 'args' => [],
513+ * ],
514+ * ],
515+ * ],
516+ * ],
517+ * 'alias1' => [
518+ * 'args' => [],
519+ * 'selectionSet' => [
520+ * 'nested1' => [
521+ * 'nested1' => [
522+ * 'args' => [
523+ * 'myArg' => 2,
524+ * 'mySecondAg' => "test,
525+ * ],
526+ * ],
527+ * ],
528+ * ],
529+ * ],
530+ * ],
531+ * ]
532+ *
533+ * This method does not consider conditional typed fragments.
534+ * Use it with care for fields of interface and union types.
535+ * You can still alias the union type fields with the same name in order to extract their corresponding args.
536+ *
537+ * Example:
538+ * {
539+ * root {
540+ * id
541+ * unionPerson {
542+ * ...on Child {
543+ * name
544+ * birthdate(format: "d/m/Y")
545+ * }
546+ * ...on Adult {
547+ * adultName: name
548+ * adultBirthDate: birthdate(format: "Y-m-d")
549+ * job
550+ * }
551+ * }
552+ * }
553+ * }
554+ *
555+ * @param int $depth How many levels to include in the output beyond the first
556+ *
557+ * @throws \Exception
558+ * @throws Error
559+ * @throws InvariantViolation
560+ *
561+ * @return array<string , mixed >
562+ *
563+ * @api
564+ */
565+ function getFieldSelectionWithAliases(int $depth = 0): array
566+ ```
567+
472568## GraphQL\Language\DirectiveLocation
473569
474570Enumeration of available directive locations.
0 commit comments