Skip to content

Commit f13161a

Browse files
vinceAmstoutzmauriau
and
mauriau
authored
feat(graphql): enable configurable max_query_depth and max_query_complexity (#2128)
* feat(graphql): allow to change max_query_depth and max_query_complexity * docs(graphql): support laravel for max_query_depth & max_query_complexity --------- Co-authored-by: mauriau <m.auriau@toovalu.com>
1 parent 5ac9eaa commit f13161a

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

core/configuration.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ api_platform:
155155

156156
# The nesting separator used in the filter names.
157157
nesting_separator: _
158-
158+
159+
# The maximum query depth. Set to 0 to disable it. Look at https://webonyx.github.io/graphql-php/security/#limiting-query-depth
160+
max_query_depth: 20
161+
162+
# The maximum query complexity. Set to 0 to disable it. Look at https://webonyx.github.io/graphql-php/security/#query-complexity-analysis
163+
max_query_complexity: 500
164+
159165
collection:
160166
pagination:
161167
enabled: true
@@ -545,6 +551,12 @@ return [
545551

546552
// The nesting separator used in the filter names.
547553
'nesting_separator' => '_',
554+
555+
// The maximum query depth. Set to 0 to disable it. Look at https://webonyx.github.io/graphql-php/security/#limiting-query-depth
556+
'max_query_depth' => 20,
557+
558+
// The maximum query complexity. Set to 0 to disable it. Look at https://webonyx.github.io/graphql-php/security/#query-complexity-analysis
559+
'max_query_complexity' => 500,
548560

549561
'collection' => [
550562
'pagination' => [

core/graphql.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,68 @@ return [
254254
];
255255
```
256256

257+
## Change Max Query Depth
258+
259+
For security reason, the max query depth should be limited to avoid deep queries. **It's set to 100 by default**.
260+
261+
### Symfony config to change the Max Query Depth
262+
263+
If you need to change it, it can be done in the configuration:
264+
265+
```yaml
266+
# api/config/packages/api_platform.yaml
267+
api_platform:
268+
graphql:
269+
max_query_depth: 7
270+
# ...
271+
```
272+
273+
### Laravel config to change the Max Query Depth
274+
275+
If you need to change it, it can be done in the configuration:
276+
277+
```php
278+
<?php
279+
// config/api-platform.php
280+
return [
281+
// ....
282+
'graphql' => [
283+
'max_query_depth' => 7,
284+
],
285+
];
286+
```
287+
288+
## Change Max Query Complexity
289+
290+
For security reason, the max query complexity should be limited to avoid complex queries. **It's set to 100 by default**.
291+
292+
### Symfony config to change the Max Query Complexity
293+
294+
If you need to change it, it can be done in the configuration:
295+
296+
```yaml
297+
# api/config/packages/api_platform.yaml
298+
api_platform:
299+
graphql:
300+
max_query_complexity: 50
301+
# ...
302+
```
303+
304+
### Laravel config to change the Max Query Complexity
305+
306+
If you need to change it, it can be done in the configuration:
307+
308+
```php
309+
<?php
310+
// config/api-platform.php
311+
return [
312+
// ....
313+
'graphql' => [
314+
'max_query_complexity' => 50,
315+
],
316+
];
317+
```
318+
257319
## Request with `application/graphql` Content-Type
258320

259321
If you wish to send a [POST request using the `application/graphql` Content-Type](https://graphql.org/learn/serving-over-http/#post-request),

0 commit comments

Comments
 (0)