File tree Expand file tree Collapse file tree 2 files changed +65
-1
lines changed Expand file tree Collapse file tree 2 files changed +65
-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,67 @@ 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
+
99
+ The above allows you to find offers by their respective product's color like for the REST Api.
100
+ You can then filter using the following syntax:
101
+
102
+ ``` graphql
103
+ {
104
+ offers (product_color : " red" ) {
105
+ edges {
106
+ node {
107
+ id
108
+ product {
109
+ name
110
+ color
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ Or order your results like:
119
+
120
+ ``` graphql
121
+ {
122
+ offers (order : {product_releaseDate : " DESC" }) {
123
+ edges {
124
+ node {
125
+ id
126
+ product {
127
+ name
128
+ color
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+ ```
You can’t perform that action at this time.
0 commit comments