@@ -42,6 +42,7 @@ pub struct Query {
42
42
/// have dummy values
43
43
pub ( crate ) query_text : Arc < String > ,
44
44
pub ( crate ) variables_text : Arc < String > ,
45
+ pub ( crate ) complexity : u64 ,
45
46
}
46
47
47
48
impl Query {
@@ -88,7 +89,7 @@ impl Query {
88
89
q:: OperationDefinition :: Query ( q:: Query { selection_set, .. } ) => {
89
90
( Kind :: Query , selection_set)
90
91
}
91
- // Queries can be run by just sending a selction set
92
+ // Queries can be run by just sending a selection set
92
93
q:: OperationDefinition :: SelectionSet ( selection_set) => ( Kind :: Query , selection_set) ,
93
94
q:: OperationDefinition :: Subscription ( q:: Subscription { selection_set, .. } ) => {
94
95
( Kind :: Subscription , selection_set)
@@ -100,20 +101,21 @@ impl Query {
100
101
}
101
102
} ;
102
103
103
- let query = Arc :: new ( Self {
104
+ let mut query = Self {
104
105
schema : query. schema ,
105
106
variables,
106
107
fragments,
107
108
selection_set,
108
109
kind,
109
110
query_text,
110
111
variables_text,
111
- } ) ;
112
+ complexity : 0 ,
113
+ } ;
112
114
113
115
query. validate_fields ( ) ?;
114
116
query. check_complexity ( max_complexity, max_depth) ?;
115
117
116
- Ok ( query)
118
+ Ok ( Arc :: new ( query) )
117
119
}
118
120
119
121
/// Return the block constraint for the toplevel query field(s) Since,
@@ -161,6 +163,7 @@ impl Query {
161
163
kind : self . kind ,
162
164
query_text : self . query_text . clone ( ) ,
163
165
variables_text : self . variables_text . clone ( ) ,
166
+ complexity : self . complexity ,
164
167
} )
165
168
}
166
169
@@ -186,7 +189,7 @@ impl Query {
186
189
}
187
190
188
191
fn check_complexity (
189
- & self ,
192
+ & mut self ,
190
193
max_complexity : Option < u64 > ,
191
194
max_depth : u8 ,
192
195
) -> Result < ( ) , Vec < QueryExecutionError > > {
@@ -198,6 +201,7 @@ impl Query {
198
201
max_complexity,
199
202
) ] ) ;
200
203
}
204
+ self . complexity = complexity;
201
205
}
202
206
Ok ( ( ) )
203
207
}
0 commit comments