@@ -194,18 +194,21 @@ impl Query {
194
194
Ok ( Arc :: new ( query) )
195
195
}
196
196
197
- /// Return the block constraint for the toplevel query field(s), merging the selection sets of
198
- /// fields that have the same block constraint.
197
+ /// Return the block constraint for the toplevel query field(s), merging
198
+ /// consecutive fields that have the same block constraint, while making
199
+ /// sure that the fields appear in the same order as they did in the
200
+ /// query
199
201
///
200
- /// Also returns the combined error policy for those fields, which is `Deny` if any field is
201
- /// `Deny` and `Allow` otherwise.
202
+ /// Also returns the combined error policy for those fields, which is
203
+ /// `Deny` if any field is `Deny` and `Allow` otherwise.
202
204
pub fn block_constraint (
203
205
& self ,
204
- ) -> Result < HashMap < BlockConstraint , ( a:: SelectionSet , ErrorPolicy ) > , Vec < QueryExecutionError > >
206
+ ) -> Result < Vec < ( BlockConstraint , ( a:: SelectionSet , ErrorPolicy ) ) > , Vec < QueryExecutionError > >
205
207
{
206
- let mut bcs = HashMap :: new ( ) ;
208
+ let mut bcs: Vec < ( BlockConstraint , ( a :: SelectionSet , ErrorPolicy ) ) > = Vec :: new ( ) ;
207
209
208
210
let root_type = self . schema . query_type . as_ref ( ) ;
211
+ let mut prev_bc: Option < BlockConstraint > = None ;
209
212
for field in self . selection_set . fields_for ( root_type) {
210
213
let bc = match field. argument_value ( "block" ) {
211
214
Some ( bc) => BlockConstraint :: try_from_value ( bc) . map_err ( |_| {
@@ -229,16 +232,19 @@ impl Query {
229
232
None => ErrorPolicy :: Deny ,
230
233
} ;
231
234
232
- let ( selection_set, error_policy) = bcs. entry ( bc) . or_insert_with ( || {
233
- (
234
- a:: SelectionSet :: empty_from ( & self . selection_set ) ,
235
- field_error_policy,
236
- )
237
- } ) ;
238
- selection_set. push ( field) ;
239
- if field_error_policy == ErrorPolicy :: Deny {
240
- * error_policy = ErrorPolicy :: Deny ;
235
+ let next_bc = Some ( bc. clone ( ) ) ;
236
+ if prev_bc == next_bc {
237
+ let ( selection_set, error_policy) = & mut bcs. last_mut ( ) . unwrap ( ) . 1 ;
238
+ selection_set. push ( field) ;
239
+ if field_error_policy == ErrorPolicy :: Deny {
240
+ * error_policy = ErrorPolicy :: Deny ;
241
+ }
242
+ } else {
243
+ let mut selection_set = a:: SelectionSet :: empty_from ( & self . selection_set ) ;
244
+ selection_set. push ( field) ;
245
+ bcs. push ( ( bc, ( selection_set, field_error_policy) ) )
241
246
}
247
+ prev_bc = next_bc;
242
248
}
243
249
Ok ( bcs)
244
250
}
0 commit comments