25
25
use GraphQL \Server \Helper ;
26
26
use GraphQL \Type \Definition \ResolveInfo ;
27
27
use GraphQL \Validator \DocumentValidator ;
28
+ use GraphQL \Validator \Rules \DisableIntrospection ;
29
+ use GraphQL \Validator \Rules \QueryComplexity ;
30
+ use GraphQL \Validator \Rules \QueryDepth ;
28
31
29
32
/**
30
33
* The main GraphQL configuration and request entry point.
59
62
* "endpoint",
60
63
* "debug_flag",
61
64
* "caching",
62
- * "batching"
65
+ * "batching",
66
+ * "disable_introspection",
67
+ * "query_depth",
68
+ * "query_complexity"
63
69
* },
64
70
* links = {
65
71
* "collection" = "/admin/config/graphql/servers",
@@ -123,6 +129,27 @@ class Server extends ConfigEntityBase implements ServerInterface {
123
129
*/
124
130
public $ batching = TRUE ;
125
131
132
+ /**
133
+ * Whether to disable query introspection.
134
+ *
135
+ * @var bool
136
+ */
137
+ public $ disable_introspection = FALSE ;
138
+
139
+ /**
140
+ * The query complexity.
141
+ *
142
+ * @var int|null
143
+ */
144
+ public $ query_complexity = NULL ;
145
+
146
+ /**
147
+ * The query depth.
148
+ *
149
+ * @var int|null
150
+ */
151
+ public $ query_depth = NULL ;
152
+
126
153
/**
127
154
* The server's endpoint.
128
155
*
@@ -137,7 +164,6 @@ class Server extends ConfigEntityBase implements ServerInterface {
137
164
*/
138
165
public $ persisted_queries_settings = [];
139
166
140
-
141
167
/**
142
168
* Persisted query plugin instances available on this server.
143
169
*
@@ -498,10 +524,90 @@ protected function getValidationRules() {
498
524
return [];
499
525
}
500
526
501
- return array_values (DocumentValidator::defaultRules ());
527
+ $ rules = array_values (DocumentValidator::defaultRules ());
528
+ if ($ this ->getDisableIntrospection ()) {
529
+ $ rules [] = new DisableIntrospection ();
530
+ }
531
+ if ($ this ->getQueryDepth ()) {
532
+ $ rules [] = new QueryDepth ($ this ->getQueryDepth ());
533
+ }
534
+ if ($ this ->getQueryComplexity ()) {
535
+ $ rules [] = new QueryComplexity ($ this ->getQueryComplexity ());
536
+ }
537
+
538
+ return $ rules ;
502
539
};
503
540
}
504
541
542
+ /**
543
+ * Gets disable introspection config.
544
+ *
545
+ * @return bool
546
+ * The disable introspection config, FALSE otherwise.
547
+ */
548
+ public function getDisableIntrospection (): bool {
549
+ return (bool ) $ this ->disable_introspection ;
550
+ }
551
+
552
+ /**
553
+ * Sets disable introspection config.
554
+ *
555
+ * @param bool $introspection
556
+ * The value for the disable introspection config.
557
+ *
558
+ * @return $this
559
+ */
560
+ public function setDisableIntrospection (bool $ introspection ) {
561
+ $ this ->disable_introspection = $ introspection ;
562
+ return $ this ;
563
+ }
564
+
565
+ /**
566
+ * Gets query depth config.
567
+ *
568
+ * @return int|null
569
+ * The query depth, NULL otherwise.
570
+ */
571
+ public function getQueryDepth (): ?int {
572
+ return (int ) $ this ->query_depth ;
573
+ }
574
+
575
+ /**
576
+ * Sets query depth config.
577
+ *
578
+ * @param int|null $depth
579
+ * The value for the query depth config.
580
+ *
581
+ * @return $this
582
+ */
583
+ public function setQueryDepth (?int $ depth ) {
584
+ $ this ->query_depth = $ depth ;
585
+ return $ this ;
586
+ }
587
+
588
+ /**
589
+ * Gets query complexity config.
590
+ *
591
+ * @return int|null
592
+ * The query complexity, NULL otherwise.
593
+ */
594
+ public function getQueryComplexity (): ?int {
595
+ return (int ) $ this ->query_complexity ;
596
+ }
597
+
598
+ /**
599
+ * Sets query complexity config.
600
+ *
601
+ * @param int|null $complexity
602
+ * The value for the query complexity config.
603
+ *
604
+ * @return $this
605
+ */
606
+ public function setQueryComplexity (?int $ complexity ) {
607
+ $ this ->query_complexity = $ complexity ;
608
+ return $ this ;
609
+ }
610
+
505
611
/**
506
612
* {@inheritDoc}
507
613
*/
0 commit comments