You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Upgrade PHPStan
- Uninstall deprecated phpstan-shim
- Remove all unmatched ignored errors from phpstan-baseline.neon
- Rename phpstan.neon.dist (remove .dist suffix)
- Upgrade PHPUnit to the latest
- Change deprecated test methods accordingly
- Update all Symfony version constraints to ^4.4 || ^5.0
- Configure new PHP-CS-Fixer rules:
- Remove all unnecessary annotations
Manually go through all files and change/fix/tweak code, add type-hints wherever possible.
Copy file name to clipboardExpand all lines: docs/annotations/index.md
+28-30
Original file line number
Diff line number
Diff line change
@@ -50,47 +50,46 @@ If you use mutations, you need a `RootMutation` type as well.
50
50
51
51
## Annotations & type inheritance
52
52
53
-
As PHP classes naturally support inheritances (and so is the annotation reader), it doesn't make sense to allow classes to use the "inherits" option.
54
-
The type will inherits the annotations declared on parent classes properties and methods. The annotation on the class itself will not be herited.
55
-
53
+
As PHP classes naturally support inheritance (and so is the annotation reader), it doesn't make sense to allow classes to use the "inherits" option (as on types declared using YAML).
54
+
The type will inherit annotations declared on parent class properties and methods. The annotation on the class itself will not be inherited.
56
55
57
56
## Annotations, value & default resolver
58
57
59
-
In GraphQL, when a type's field is resolved, GraphQL expect by default a property (for object) or an index (for array) on the corresponding value returned for the type.
58
+
In GraphQL, when a type's field is resolved, GraphQL expects by default a property (for object) or a key (for array) on the corresponding value returned for the type.
60
59
61
-
For example, if I have a type like that :
60
+
For example, if you have a type like that :
62
61
63
62
```graphql
64
63
type Character {
65
64
name: String!
66
65
}
67
66
```
68
67
69
-
If the field `name` is queried, on a `Character` type instance, the default resolver will try to find a property or index on the related object (the `value`).
70
-
So, the value could be an object instance with a `name` property or an array with a `name` index.
68
+
If the field `name` is queried, on a `Character` type instance, the default resolver will try to find a property or key on the related variable (the `value`).
69
+
So, the `value` could be an object instance with a `name` property or an array with a `name` key.
71
70
72
-
Except for the root query and the root mutation, the value object is always returned by an other resolver.
73
-
For the Root query and the root mutation, the value object is the service with an id equals to the fully qualified name of the query/mutation class.
71
+
Except for the root Query and root Mutation types, the `value` variable is always returned by another resolver.
72
+
For the root Query and the Root Mutation types, the `value` variable is the service with an id that equals to the fully qualified name of the query/mutation class.
74
73
75
-
On a `@Field` or `@Query` or `@Mutation`, the following rules apply to guess a resolver when no `resolver` attribute is define on the annotation:
74
+
The following rules apply for `@Field`, `@Query` and `@Mutation` annotations to guess a resolver when no `resolver` attribute is defined:
76
75
77
-
- If the `@Field` apply on a property :
78
-
- If the `@Field` attribute `name` is define and not equals to the property name
79
-
- `@=value.[property name]`for a regular type
80
-
- `@=service([FQN class]).[property name]`for root query or root mutation
76
+
- If `@Field` is defined on a property :
77
+
- If `@Field`'s attribute `name` is defined and is not equal to the property name
78
+
- `@=value.<property name>`for a regular type
79
+
- `@=service(<FQCN>).<property name>`for root query or root mutation
81
80
82
-
- If the `@Field` attribute `name` is not define or equals the property
81
+
- If `@Field`'s attribute `name` is not defined or is not equal to the property name
83
82
- The default GraphQL resolver will be use for a regular type (no `resolve` configuration will be define).
84
-
- `@=service([FQN class]).[name]`for root query or root mutation
83
+
- `@=service(<FQCN>).<name>`for root query or root mutation
85
84
86
-
- If the `@Field` apply on a method :
87
-
- `@=call(value.[method name], args)`for a regular type
88
-
- `@=call(service([FQN class]).[method name], args)`for root query or mutation
85
+
- If `@Field` is defined on a method :
86
+
- `@=call(value.<method name>, args)`for a regular type
87
+
- `@=call(service(<FQCN>).<method name>, args)`for root query or mutation
89
88
90
89
91
90
## Annotations, Root Query & Root Mutation
92
91
93
-
If you define your Root Query, or Root Mutation as a class with annotations, it will allow you to define methods directly on the class itself to be expose as GraphQL.
92
+
If you define your root Query or root Mutation type as a class with annotations, it will allow you to define methods directly on the class itself to be exposed as GraphQL fields.
94
93
For example:
95
94
96
95
```php
@@ -109,8 +108,8 @@ class RootQuery {
109
108
}
110
109
```
111
110
112
-
In order for this to work, the Root Query class must be instanciated at some point if we want to be able to call methods on it.
113
-
To do so, the RootQuery class must be define as a service with the class fully qualified name as id.
111
+
In order for this to work, the `RootQuery` class must be instanciated at some point if you want to be able to call methods on it.
112
+
To do so, the `RootQuery` class must be defined as a service with its FQCN as id.
114
113
In the previous example, we need a service name `App\GraphQL\Query\RootQuery`. It works the same way for mutations.
115
114
In the previous example, the generated `resolve` config of the `something` field will be `@=service('App\GraphQL\Query\RootQuery').getSomething()`.
116
115
@@ -121,9 +120,9 @@ In the previous example, the generated `resolve` config of the `something` field
121
120
122
121
Based on other Doctrine annotations on your fields, the corresponding GraphQL type can sometimes be guessed automatically.
123
122
124
-
The type can be auto-guess from :
123
+
The type can be auto-guessed from the following annotations:
125
124
126
-
- `@ORM\Column`annotations, based on the `type` attribute
125
+
- `@ORM\Column`, based on the `type` attribute
127
126
- `@ORM\ManyToOne`, `@ORM\ManyToMany`, `@ORM\OneToOne`, `@ORM\OneToMany`, based on the `targetEntity` attribute. The target entity must be a GraphQL type itself to work.
128
127
- `@ORM\ManyToOne`, `@ORM\OneToOne` The generated type will also use the `@ORM\JoinColumn` annotation and his `nullable` attribute to generate either `Type` or `Type!`
129
128
- `@ORM\ManyToMany`, `@ORM\OneToMany` The generated type will always be not null, like `[Type]!` as you're supposed to initialize corresponding properties with an ArrayCollection
@@ -143,9 +142,9 @@ overblog_graphql:
143
142
```
144
143
145
144
146
-
### @Field type auto-guessing when applied on a method with a return type hint
145
+
### @Field type auto-guessing when defined on a method with a return type hint
147
146
148
-
The type of a `@Field` annotation can be auto-guessed if it applies on a method with a return type hint.
147
+
The type of the `@Field` annotation can be auto-guessed if it's defined on a method with a return type hint.
149
148
150
149
For example:
151
150
@@ -165,9 +164,9 @@ class MyType {
165
164
166
165
In this example, the type `String!` will be auto-guessed from the return type hint of the method.
167
166
168
-
### @Field arguments auto-guessing when applied on a method with type hinted parameters
167
+
### @Field arguments auto-guessing when defined on a method with type hinted parameters
169
168
170
-
The arguments of a `@Field` annotation can be auto-guessed if it applies on a method with type hinted arguments. Arguments without default value will be consided required.
169
+
The arguments of the `@Field` annotation can be auto-guessed if it's defined on a method with type hinted arguments. Arguments without default value will be consided required.
171
170
172
171
For example:
173
172
@@ -194,7 +193,7 @@ The GraphQL arguments will be auto-guessed as:
194
193
195
194
### Limitation of auto-guessing:
196
195
197
-
When trying to auto-guess type or args based on PHP Reflection (from type hinted method parameters or type hinted return value), there is a limitation.
196
+
When trying to auto-guess a type or args based on PHP Reflection (from type hinted method parameters or type hinted return value), there is a limitation.
198
197
As PHP type hinting doesn't support "array of instances of class", we cannot rely on it to guess the type when dealing with collection of objects.
199
198
In these case, you'll need to declare your types or arguments type manually.
200
199
@@ -206,4 +205,3 @@ For example, in PHP, a signature like this : `public function getArrayOfStrings(
0 commit comments