File tree Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Expand file tree Collapse file tree 2 files changed +64
-1
lines changed Original file line number Diff line number Diff line change @@ -508,7 +508,7 @@ use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
508
508
/**
509
509
* @ApiResource
510
510
* @ApiFilter(OrderFilter::class, properties={"product.releaseDate"})
511
- * @ApiFilter(SearchFilter::class, properties={"product.name ": "exact"})
511
+ * @ApiFilter(SearchFilter::class, properties={"product.color ": "exact"})
512
512
*/
513
513
class Offer
514
514
{
Original file line number Diff line number Diff line change @@ -68,3 +68,66 @@ class Offer
68
68
// ...
69
69
}
70
70
```
71
+
72
+ ### Filtering on Nested Properties
73
+
74
+ Unlike for REST, all built-in filters support nested properties using the underscore (` _ ` ) syntax instead of the dot (` . ` ) syntax, e.g.:
75
+
76
+ ``` php
77
+ <?php
78
+ // api/src/Entity/Offer.php
79
+
80
+ namespace App\Entity;
81
+
82
+ use ApiPlatform\Core\Annotation\ApiFilter;
83
+ use ApiPlatform\Core\Annotation\ApiResource;
84
+ use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
85
+ use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
86
+
87
+ /**
88
+ * @ApiResource
89
+ * @ApiFilter(OrderFilter::class, properties={"product.releaseDate"})
90
+ * @ApiFilter(SearchFilter::class, properties={"product.color": "exact"})
91
+ */
92
+ class Offer
93
+ {
94
+ // ...
95
+ }
96
+ ```
97
+
98
+ The above allows you to find offers by their respective product's color like for the REST Api.
99
+ You can then filter using the following syntax:
100
+
101
+ ``` graphql
102
+ {
103
+ offers (product_color : " red" ) {
104
+ edges {
105
+ node {
106
+ id
107
+ product {
108
+ name
109
+ color
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ Or order your results like:
118
+
119
+ ``` graphql
120
+ {
121
+ offers (order : {product_releaseDate : " DESC" }) {
122
+ edges {
123
+ node {
124
+ id
125
+ product {
126
+ name
127
+ color
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+ ```
You can’t perform that action at this time.
0 commit comments