@@ -21,6 +21,11 @@ use graph::{
21
21
data:: query:: { QueryResults , QueryTarget } ,
22
22
prelude:: QueryStore ,
23
23
} ;
24
+ use graphql_tools:: validation:: rules:: {
25
+ FragmentsOnCompositeTypes , KnownFragmentNamesRule , LeafFieldSelections , LoneAnonymousOperation ,
26
+ NoUnusedFragments , OverlappingFieldsCanBeMerged ,
27
+ } ;
28
+ use graphql_tools:: validation:: validate:: ValidationPlan ;
24
29
25
30
use lazy_static:: lazy_static;
26
31
@@ -77,6 +82,7 @@ pub struct GraphQlRunner<S, SM> {
77
82
subscription_manager : Arc < SM > ,
78
83
load_manager : Arc < LoadManager > ,
79
84
result_size : Arc < ResultSizeMetrics > ,
85
+ pub graphql_validation_plan : Arc < ValidationPlan > ,
80
86
}
81
87
82
88
lazy_static ! {
@@ -86,6 +92,10 @@ lazy_static! {
86
92
u64 :: from_str( & s)
87
93
. unwrap_or_else( |_| panic!( "failed to parse env var GRAPH_GRAPHQL_QUERY_TIMEOUT" ) )
88
94
) ) ;
95
+ static ref DISABLE_GRAPHQL_VALIDATIONS : bool = std:: env:: var( "DISABLE_GRAPHQL_VALIDATIONS" )
96
+ . unwrap_or_else( |_| "false" . into( ) )
97
+ . parse:: <bool >( )
98
+ . unwrap_or_else( |_| false ) ;
89
99
static ref GRAPHQL_MAX_COMPLEXITY : Option <u64 > = env:: var( "GRAPH_GRAPHQL_MAX_COMPLEXITY" )
90
100
. ok( )
91
101
. map( |s| u64 :: from_str( & s)
@@ -135,12 +145,24 @@ where
135
145
) -> Self {
136
146
let logger = logger. new ( o ! ( "component" => "GraphQlRunner" ) ) ;
137
147
let result_size = Arc :: new ( ResultSizeMetrics :: new ( registry) ) ;
148
+ let mut graphql_validation_plan = ValidationPlan { rules : Vec :: new ( ) } ;
149
+
150
+ if !( * DISABLE_GRAPHQL_VALIDATIONS ) {
151
+ graphql_validation_plan. add_rule ( Box :: new ( LoneAnonymousOperation { } ) ) ;
152
+ graphql_validation_plan. add_rule ( Box :: new ( FragmentsOnCompositeTypes { } ) ) ;
153
+ graphql_validation_plan. add_rule ( Box :: new ( OverlappingFieldsCanBeMerged { } ) ) ;
154
+ graphql_validation_plan. add_rule ( Box :: new ( KnownFragmentNamesRule { } ) ) ;
155
+ graphql_validation_plan. add_rule ( Box :: new ( NoUnusedFragments { } ) ) ;
156
+ graphql_validation_plan. add_rule ( Box :: new ( LeafFieldSelections { } ) ) ;
157
+ }
158
+
138
159
GraphQlRunner {
139
160
logger,
140
161
store,
141
162
subscription_manager,
142
163
load_manager,
143
164
result_size,
165
+ graphql_validation_plan : Arc :: new ( graphql_validation_plan) ,
144
166
}
145
167
}
146
168
@@ -212,6 +234,7 @@ where
212
234
schema,
213
235
network,
214
236
query,
237
+ self . graphql_validation_plan . clone ( ) ,
215
238
max_complexity,
216
239
max_depth,
217
240
) ?;
@@ -317,6 +340,7 @@ where
317
340
schema,
318
341
Some ( network. clone ( ) ) ,
319
342
subscription. query ,
343
+ self . graphql_validation_plan . clone ( ) ,
320
344
* GRAPHQL_MAX_COMPLEXITY ,
321
345
* GRAPHQL_MAX_DEPTH ,
322
346
) ?;
0 commit comments