@@ -300,15 +300,20 @@ fn operation_matches(
300
300
this : & SubgraphOperation ,
301
301
other : & SubgraphOperation ,
302
302
) -> Result < ( ) , MatchFailure > {
303
- let this_ast = match ast:: Document :: parse ( this. as_serialized ( ) , "this_operation.graphql" ) {
303
+ document_str_matches ( this. as_serialized ( ) , other. as_serialized ( ) )
304
+ }
305
+
306
+ // Compare operation document strings such as query or just selection set.
307
+ fn document_str_matches ( this : & str , other : & str ) -> Result < ( ) , MatchFailure > {
308
+ let this_ast = match ast:: Document :: parse ( this, "this_operation.graphql" ) {
304
309
Ok ( document) => document,
305
310
Err ( _) => {
306
311
return Err ( MatchFailure :: new (
307
312
"Failed to parse this operation" . to_string ( ) ,
308
313
) ) ;
309
314
}
310
315
} ;
311
- let other_ast = match ast:: Document :: parse ( other. as_serialized ( ) , "other_operation.graphql" ) {
316
+ let other_ast = match ast:: Document :: parse ( other, "other_operation.graphql" ) {
312
317
Ok ( document) => document,
313
318
Err ( _) => {
314
319
return Err ( MatchFailure :: new (
@@ -319,6 +324,20 @@ fn operation_matches(
319
324
same_ast_document ( & this_ast, & other_ast)
320
325
}
321
326
327
+ fn opt_document_string_matches (
328
+ this : & Option < String > ,
329
+ other : & Option < String > ,
330
+ ) -> Result < ( ) , MatchFailure > {
331
+ match ( this, other) {
332
+ ( None , None ) => Ok ( ( ) ) ,
333
+ ( Some ( this_sel) , Some ( other_sel) ) => document_str_matches ( this_sel, other_sel) ,
334
+ _ => Err ( MatchFailure :: new ( format ! (
335
+ "mismatched at opt_document_string_matches\n left: {:?}\n right: {:?}" ,
336
+ this, other
337
+ ) ) ) ,
338
+ }
339
+ }
340
+
322
341
// The rest is calling the comparison functions above instead of `PartialEq`,
323
342
// but otherwise behave just like `PartialEq`:
324
343
@@ -494,8 +513,8 @@ fn plan_node_matches(this: &PlanNode, other: &PlanNode) -> Result<(), MatchFailu
494
513
deferred : other_deferred,
495
514
} ,
496
515
) => {
497
- check_match ! ( defer_primary_node_matches( primary, other_primary) ) ;
498
- check_match ! ( vec_matches ( deferred, other_deferred, deferred_node_matches) ) ;
516
+ defer_primary_node_matches ( primary, other_primary) ? ;
517
+ vec_matches_result ( deferred, other_deferred, deferred_node_matches) ? ;
499
518
}
500
519
(
501
520
PlanNode :: Subscription { primary, rest } ,
@@ -536,24 +555,30 @@ fn plan_node_matches(this: &PlanNode, other: &PlanNode) -> Result<(), MatchFailu
536
555
Ok ( ( ) )
537
556
}
538
557
539
- fn defer_primary_node_matches ( this : & Primary , other : & Primary ) -> bool {
558
+ fn defer_primary_node_matches ( this : & Primary , other : & Primary ) -> Result < ( ) , MatchFailure > {
540
559
let Primary { subselection, node } = this;
541
- * subselection == other. subselection && opt_plan_node_matches ( node, & other. node ) . is_ok ( )
560
+ opt_document_string_matches ( subselection, & other. subselection )
561
+ . map_err ( |err| err. add_description ( "under defer primary subselection" ) ) ?;
562
+ opt_plan_node_matches ( node, & other. node )
563
+ . map_err ( |err| err. add_description ( "under defer primary plan node" ) )
542
564
}
543
565
544
- fn deferred_node_matches ( this : & DeferredNode , other : & DeferredNode ) -> bool {
566
+ fn deferred_node_matches ( this : & DeferredNode , other : & DeferredNode ) -> Result < ( ) , MatchFailure > {
545
567
let DeferredNode {
546
568
depends,
547
569
label,
548
570
query_path,
549
571
subselection,
550
572
node,
551
573
} = this;
552
- * depends == other. depends
553
- && * label == other. label
554
- && * query_path == other. query_path
555
- && * subselection == other. subselection
556
- && opt_plan_node_matches ( node, & other. node ) . is_ok ( )
574
+
575
+ check_match_eq ! ( * depends, other. depends) ;
576
+ check_match_eq ! ( * label, other. label) ;
577
+ check_match_eq ! ( * query_path, other. query_path) ;
578
+ opt_document_string_matches ( subselection, & other. subselection )
579
+ . map_err ( |err| err. add_description ( "under deferred subselection" ) ) ?;
580
+ opt_plan_node_matches ( node, & other. node )
581
+ . map_err ( |err| err. add_description ( "under deferred node" ) )
557
582
}
558
583
559
584
fn flatten_node_matches ( this : & FlattenNode , other : & FlattenNode ) -> Result < ( ) , MatchFailure > {
0 commit comments