@@ -246,18 +246,21 @@ impl Query {
246
246
Ok ( Arc :: new ( query) )
247
247
}
248
248
249
- /// Return the block constraint for the toplevel query field(s), merging the selection sets of
250
- /// fields that have the same block constraint.
249
+ /// Return the block constraint for the toplevel query field(s), merging
250
+ /// consecutive fields that have the same block constraint, while making
251
+ /// sure that the fields appear in the same order as they did in the
252
+ /// query
251
253
///
252
- /// Also returns the combined error policy for those fields, which is `Deny` if any field is
253
- /// `Deny` and `Allow` otherwise.
254
+ /// Also returns the combined error policy for those fields, which is
255
+ /// `Deny` if any field is `Deny` and `Allow` otherwise.
254
256
pub fn block_constraint (
255
257
& self ,
256
- ) -> Result < HashMap < BlockConstraint , ( a:: SelectionSet , ErrorPolicy ) > , Vec < QueryExecutionError > >
258
+ ) -> Result < Vec < ( BlockConstraint , ( a:: SelectionSet , ErrorPolicy ) ) > , Vec < QueryExecutionError > >
257
259
{
258
- let mut bcs = HashMap :: new ( ) ;
260
+ let mut bcs: Vec < ( BlockConstraint , ( a :: SelectionSet , ErrorPolicy ) ) > = Vec :: new ( ) ;
259
261
260
262
let root_type = self . schema . query_type . as_ref ( ) ;
263
+ let mut prev_bc: Option < BlockConstraint > = None ;
261
264
for field in self . selection_set . fields_for ( root_type) {
262
265
let bc = match field. argument_value ( "block" ) {
263
266
Some ( bc) => BlockConstraint :: try_from_value ( bc) . map_err ( |_| {
@@ -281,16 +284,19 @@ impl Query {
281
284
None => ErrorPolicy :: Deny ,
282
285
} ;
283
286
284
- let ( selection_set, error_policy) = bcs. entry ( bc) . or_insert_with ( || {
285
- (
286
- a:: SelectionSet :: empty_from ( & self . selection_set ) ,
287
- field_error_policy,
288
- )
289
- } ) ;
290
- selection_set. push ( field) ;
291
- if field_error_policy == ErrorPolicy :: Deny {
292
- * error_policy = ErrorPolicy :: Deny ;
287
+ let next_bc = Some ( bc. clone ( ) ) ;
288
+ if prev_bc == next_bc {
289
+ let ( selection_set, error_policy) = & mut bcs. last_mut ( ) . unwrap ( ) . 1 ;
290
+ selection_set. push ( field) ;
291
+ if field_error_policy == ErrorPolicy :: Deny {
292
+ * error_policy = ErrorPolicy :: Deny ;
293
+ }
294
+ } else {
295
+ let mut selection_set = a:: SelectionSet :: empty_from ( & self . selection_set ) ;
296
+ selection_set. push ( field) ;
297
+ bcs. push ( ( bc, ( selection_set, field_error_policy) ) )
293
298
}
299
+ prev_bc = next_bc;
294
300
}
295
301
Ok ( bcs)
296
302
}
0 commit comments