File tree Expand file tree Collapse file tree 1 file changed +332
-0
lines changed
dev/tests/api-functional/testsuite/Magento/GraphQl/Framework Expand file tree Collapse file tree 1 file changed +332
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \GraphQl \Framework ;
9
+
10
+ use Magento \TestFramework \TestCase \GraphQlAbstract ;
11
+
12
+ class QueryComplexityLimiterTest extends GraphQlAbstract
13
+ {
14
+ /**
15
+ * @magentoApiDataFixture Magento/Catalog/_files/product_virtual.php
16
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
17
+ */
18
+ public function testQueryComplexityIsLimited ()
19
+ {
20
+ $ query
21
+ = <<<QUERY
22
+ {
23
+ category(id: 2) {
24
+ products {
25
+ items {
26
+ name
27
+ categories {
28
+ id
29
+ position
30
+ level
31
+ url_key
32
+ url_path
33
+ product_count
34
+ breadcrumbs {
35
+ category_id
36
+ category_name
37
+ category_url_key
38
+ }
39
+ products {
40
+ items {
41
+ media_gallery_entries {
42
+ file
43
+ }
44
+ name
45
+ special_from_date
46
+ special_to_date
47
+ new_to_date
48
+ new_from_date
49
+ tier_price
50
+ manufacturer
51
+ thumbnail
52
+ sku
53
+ image
54
+ canonical_url
55
+ updated_at
56
+ created_at
57
+ categories {
58
+ id
59
+ position
60
+ level
61
+ url_key
62
+ url_path
63
+ product_count
64
+ breadcrumbs {
65
+ category_id
66
+ category_name
67
+ category_url_key
68
+ }
69
+ products {
70
+ items {
71
+ name
72
+ special_from_date
73
+ special_to_date
74
+ new_to_date
75
+ thumbnail
76
+ new_from_date
77
+ tier_price
78
+ manufacturer
79
+ sku
80
+ image
81
+ canonical_url
82
+ updated_at
83
+ created_at
84
+ media_gallery_entries {
85
+ position
86
+ id
87
+ types
88
+ }
89
+ categories {
90
+ id
91
+ position
92
+ level
93
+ url_key
94
+ url_path
95
+ product_count
96
+ breadcrumbs {
97
+ category_id
98
+ category_name
99
+ category_url_key
100
+ }
101
+ products {
102
+ items {
103
+ name
104
+ special_from_date
105
+ special_to_date
106
+ new_to_date
107
+ new_from_date
108
+ tier_price
109
+ manufacturer
110
+ thumbnail
111
+ sku
112
+ image
113
+ canonical_url
114
+ updated_at
115
+ created_at
116
+ categories {
117
+ id
118
+ position
119
+ level
120
+ url_key
121
+ url_path
122
+ product_count
123
+ breadcrumbs {
124
+ category_id
125
+ category_name
126
+ category_url_key
127
+ }
128
+ products {
129
+ items {
130
+ name
131
+ special_from_date
132
+ special_to_date
133
+ new_to_date
134
+ new_from_date
135
+ tier_price
136
+ manufacturer
137
+ sku
138
+ image
139
+ canonical_url
140
+ updated_at
141
+ created_at
142
+ categories {
143
+ id
144
+ position
145
+ level
146
+ url_key
147
+ url_path
148
+ product_count
149
+ breadcrumbs {
150
+ category_id
151
+ category_name
152
+ category_url_key
153
+ }
154
+ products {
155
+ items {
156
+ name
157
+ special_from_date
158
+ special_to_date
159
+ new_to_date
160
+ new_from_date
161
+ tier_price
162
+ manufacturer
163
+ sku
164
+ image
165
+ thumbnail
166
+ canonical_url
167
+ updated_at
168
+ created_at
169
+ categories {
170
+ id
171
+ position
172
+ level
173
+ url_key
174
+ url_path
175
+ product_count
176
+ default_sort_by
177
+ breadcrumbs {
178
+ category_id
179
+ category_name
180
+ category_url_key
181
+ }
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ QUERY ;
203
+
204
+ self ::expectExceptionMessageRegExp ('/Max query complexity should be 150 but got 151/ ' );
205
+ $ this ->graphQlQuery ($ query );
206
+ }
207
+
208
+ /**
209
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
210
+ */
211
+ public function testQueryDepthIsLimited ()
212
+ {
213
+ $ query
214
+ = <<<QUERY
215
+ {
216
+ category(id: 2) {
217
+ products {
218
+ items {
219
+ name
220
+ categories {
221
+ products {
222
+ items {
223
+ media_gallery_entries {
224
+ file
225
+ }
226
+ categories {
227
+ products {
228
+ items {
229
+ categories {
230
+ products {
231
+ items {
232
+ categories {
233
+ products {
234
+ items {
235
+ categories {
236
+ products {
237
+ items {
238
+ categories {
239
+ products {
240
+ items {
241
+ categories {
242
+ products {
243
+ items {
244
+ categories {
245
+ products {
246
+ items {
247
+ categories {
248
+ products {
249
+ items {
250
+ name,
251
+ categories {
252
+ products {
253
+ items {
254
+ categories {
255
+ products {
256
+ items {
257
+ categories{
258
+ products {
259
+ items {
260
+ categories {
261
+ products {
262
+ items {
263
+ categories {
264
+ products {
265
+ items {
266
+ categories {
267
+ products {
268
+ items {
269
+ name,
270
+ categories {
271
+ products {
272
+ items {
273
+ categories {
274
+ name
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+ }
294
+ }
295
+ }
296
+ }
297
+ }
298
+ }
299
+ }
300
+ }
301
+ }
302
+ }
303
+ }
304
+ }
305
+ }
306
+ }
307
+ }
308
+ }
309
+ }
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+ }
321
+ }
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
328
+ QUERY ;
329
+ self ::expectExceptionMessageRegExp ('/Max query depth should be 50 but got 51/ ' );
330
+ $ this ->graphQlQuery ($ query );
331
+ }
332
+ }
You can’t perform that action at this time.
0 commit comments