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
Copy file name to clipboardExpand all lines: docs/annotations/annotations-reference.md
+19-6Lines changed: 19 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Annotations reference
1
+
# Annotations / Attributes reference
2
2
3
3
In the following reference examples the line `use Overblog\GraphQLBundle\Annotation as GQL;` will be omitted.
4
4
@@ -8,7 +8,7 @@ In the following reference examples the line `use Overblog\GraphQLBundle\Annotat
8
8
9
9
- For example, `@GQL\Access("isAuthenticated()")` will be converted to `['access' => '@=isAuthenticated()']` during the compilation.
10
10
11
-
- You can use multiple type annotations on the same class. For example, if you need your class to be a GraphQL Type AND a Graphql Input, you just need to add the two annotations. Incompatible annotations or properties for a specified Type will simply be ignored.
11
+
- You can use multiple type annotations on the same class. For example, if you need your class to be a GraphQL Type AND a GraphQL Input, you just need to add the two annotations. Incompatible annotations or properties for a specified Type will simply be ignored.
12
12
13
13
In the following example, both the type `Coordinates` and the input type `CoordinatesInput` will be generated during the compilation process.
14
14
As fields on input types don't support resolvers, the field `elevation` will simply be ignored to generate the input type (it will only have two fields: `latitude` and `longitude`).
@@ -62,6 +62,8 @@ class Coordinates {
62
62
63
63
[@Input](#input)
64
64
65
+
[@InputField](#inputfield)
66
+
65
67
[@IsPublic](#ispublic)
66
68
67
69
[@Mutation](#mutation)
@@ -425,6 +427,17 @@ Optional attributes:
425
427
426
428
The corresponding class will also be used by the `Arguments Transformer` service. An instance of the corresponding class will be use as the `input` value if it is an argument of a query or mutation. (see [The Arguments Transformer documentation](arguments-transformer.md)).
427
429
430
+
## @InputField
431
+
432
+
This annotation is used in conjunction with the `@Input` annotation to define an input field.
433
+
It is the same as a regular `@Field` annotation, but it can hold a `defaultValue` and can't have a `resolver`.
434
+
435
+
Optional attributes:
436
+
437
+
-**name** : The GraphQL name of the field (default to the property name)
438
+
-**type** : The GraphqL type of the field. This attribute can sometimes be guessed automatically from Doctrine ORM annotations
439
+
-**defaultValue** : The default value of the field
440
+
428
441
## @IsPublic
429
442
430
443
Added on a _class_ in conjunction with `@Type` or `@TypeInterface`, this annotation will define the default to set if fields are public or not.
@@ -578,14 +591,14 @@ class Hero {
578
591
579
592
This annotation is used on _class_ to define a GraphQL interface.
580
593
581
-
Required attributes:
582
-
583
-
-**resolveType** : An expression to resolve the types
584
-
585
594
Optional attributes:
586
595
596
+
-**resolveType** : An expression to resolve the types
587
597
-**name** : The GraphQL name of the interface (default to the class name without namespace)
588
598
599
+
If the `resolveType` attribute is not set, the service `overblog_graphql.interface_type_resolver` will be used to try to resolve the type automatically based on types implementing the interface and their associated class.
600
+
The system will register a map of interfaces with the list of types and their associated class name implementing the interface (the parameter is named `overblog_graphql_types.interfaces_map` in the container) and use it to resolve the type from the value (the first type where the class `instanceof` operator returns true will be used).
601
+
589
602
## @Scalar
590
603
591
604
This annotation is used on a _class_ to define a custom scalar.
Copy file name to clipboardExpand all lines: docs/annotations/arguments-transformer.md
+21-47Lines changed: 21 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
# The Arguments Transformer service
2
2
3
-
When using annotation, as we use classes to describe our GraphQL objects, it is also possible to create and populate classes instances using GraphQL data.
3
+
When using attributes or annotations, as we use classes to describe our GraphQL objects, it is also possible to create and populate classes instances using GraphQL data.
4
4
If a class is used to describe a GraphQL Input, this same class can be instantiated to hold the corresponding GraphQL Input data.
5
-
This is where the `Arguments Transformer` comes into play. Knowing the matching between GraphQL types and PHP classes, the service is able to instantiate a PHP classes and populate it with data based on the corresponding GraphQL type.
5
+
This is where the `Arguments Transformer` comes into play. Knowing the matching between GraphQL types and PHP classes, the service is able to instantiate a PHP classes and populate it with data based on the corresponding GraphQL type.
6
6
To invoke the Arguments Transformer, we use the `input` expression function in our resolvers.
7
7
8
8
## the `arguments` function in expression language
9
9
10
10
The `arguments` function take two parameters, a mapping of arguments name and their type, like `name => type`. The type is in GraphQL notation, eventually with the "[]" and "!". The data are indexed by argument name.
11
11
This function will use the `Arguments Transformer` service to transform the list of arguments into their corresponding PHP class if it has one and using a property accessor, it will populate the instance, and will use the `validator` service to validate it.
12
-
The transformation is done recursively. If an Input include another Input as field, it will also be populated the same way.
12
+
The transformation is done recursively. If an Input include another Input as field, it will also be populated the same way.
13
13
14
14
For example:
15
15
@@ -19,51 +19,34 @@ namespace App\GraphQL\Input;
19
19
use Overblog\GraphQLBundle\Annotation as GQL;
20
20
use Symfony\Component\Validator\Constraints as Assert;
21
21
22
-
/**
23
-
* @GQL\Input
24
-
*/
22
+
#[GQL\Input]
25
23
class UserRegisterInput {
26
-
/**
27
-
* @GQL\Field(type="String!")
28
-
* @Assert\NotBlank
29
-
* @Assert\Length(min = 2, max = 50)
30
-
*/
24
+
#[Assert\NotBlank]
25
+
#[Assert\Length(min: 2, max: 50)]
26
+
#[GQL\Field(type: "String!")]
31
27
public $username;
32
28
33
-
/**
34
-
* @GQL\Field(type="String!")
35
-
* @Assert\NotBlank
36
-
* @Assert\Email
37
-
*/
29
+
#[Assert\NotBlank]
30
+
#[Assert\Email]
31
+
#[GQL\Field(type: "String!")]
38
32
public $email;
39
33
40
-
/**
41
-
* @GQL\Field(type="String!")
42
-
* @Assert\NotBlank
43
-
* @Assert\Length(
44
-
* min = 5,
45
-
* minMessage="The password must be at least 5 characters long."
46
-
* )
47
-
*/
34
+
#[Assert\NotBlank]
35
+
#[Assert\Length(min: 5, minMessage: "The password must be at least 5 characters long.")]
36
+
#[GQL\Field(type: "String!")]
48
37
public $password;
49
38
50
-
/**
51
-
* @GQL\Field(type="Int!")
52
-
* @Assert\NotBlank
53
-
* @Assert\GreaterThan(18)
54
-
*/
39
+
#[Assert\NotBlank]
40
+
#[Assert\GreaterThan(18)]
41
+
#[GQL\Field(type: "Int!")]
55
42
public $age;
56
43
}
57
44
58
45
....
59
46
60
-
/**
61
-
* @GQL\Provider
62
-
*/
47
+
#[GQL\Provider]
63
48
class UserRepository {
64
-
/**
65
-
* @GQL\Mutation
66
-
*/
49
+
#[GQL\Mutation]
67
50
public function createUser(UserRegisterInput $input) : User {
68
51
// Use the validated $input here
69
52
$user = new User();
@@ -81,19 +64,10 @@ The mutation received the valid instance.
81
64
In the above example, everything is auto-guessed and a Provider is used. But this would be the same as :
0 commit comments