Skip to content

Commit 52854f3

Browse files
committed
Format docs
1 parent 5f1eda3 commit 52854f3

File tree

2 files changed

+118
-18
lines changed

2 files changed

+118
-18
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ it: fix stan test docs ## Run the commonly used targets
33

44
.PHONY: help
55
help: ## Displays this list of targets with descriptions
6-
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
6+
@grep --extended-regexp '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'
77

88
.PHONY: setup
99
setup: vendor phpstan.neon ## Set up the project
1010

1111
.PHONY: fix
12-
fix: rector php-cs-fixer ## Automatic code fixes
12+
fix: rector php-cs-fixer prettier ## Automatic code fixes
1313

1414
.PHONY: rector
1515
rector: vendor ## Automatic code fixes with Rector
@@ -19,6 +19,10 @@ rector: vendor ## Automatic code fixes with Rector
1919
php-cs-fixer: vendor ## Fix code style
2020
composer php-cs-fixer
2121

22+
.PHONY: prettier
23+
prettier: ## Format code with prettier
24+
prettier --write --tab-width=2 *.md **/*.md
25+
2226
phpstan.neon:
2327
printf "includes:\n - phpstan.neon.dist" > phpstan.neon
2428

docs/class-reference.md

Lines changed: 112 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
469467
function 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

474570
Enumeration of available directive locations.

0 commit comments

Comments
 (0)