File tree Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Expand file tree Collapse file tree 1 file changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,50 @@ Scalar PHP types can be type-hinted to the corresponding GraphQL types:
27
27
28
28
GraphQL comes with a native "ID" type. PHP has no such type.
29
29
30
- TODO: develop a ID PHP class type? (for input types?)
30
+ If you want to expose an "ID" type in your GraphQL model, you have 2 solutions:
31
31
32
+ ### Solution 1: force the outputType
33
+
34
+ ``` php
35
+ /**
36
+ * @Field(outputType="ID")
37
+ */
38
+ public function getId(): string
39
+ {
40
+
41
+ }
42
+ ```
43
+
44
+ Using the "outputType" attribute of the ` @Field ` annotation, you can force the output type to "ID".
45
+ You can learn more about [ forcing output types in the "custom output types" documentation] ( custom_output_types.md ) .
46
+
47
+ ### Solution 2: use the "ID" class
48
+
49
+ ``` php
50
+ use TheCodingMachine\GraphQL\Controllers\Types\ID;
51
+
52
+ /**
53
+ * @Field
54
+ */
55
+ public function getId(): ID
56
+ {
57
+
58
+ }
59
+ ```
60
+
61
+ Note that you can also use the "ID" class as an input type:
62
+
63
+ ``` php
64
+ use TheCodingMachine\GraphQL\Controllers\Types\ID;
65
+
66
+ /**
67
+ * @Mutation
68
+ */
69
+ public function save(ID $id, string $name): Product
70
+ {
71
+
72
+ }
73
+ ```
32
74
33
75
## Mapping of dates
34
76
You can’t perform that action at this time.
0 commit comments