@@ -451,11 +451,12 @@ impl TrafficShaping {
451
451
}
452
452
453
453
pub ( crate ) fn enable_subgraph_http2 ( & self , service_name : & str ) -> bool {
454
- self . config
455
- . subgraphs
456
- . get ( service_name)
457
- . and_then ( |subgraph| subgraph. shaping . experimental_enable_http2 )
458
- . unwrap_or ( true )
454
+ Self :: merge_config (
455
+ self . config . all . as_ref ( ) ,
456
+ self . config . subgraphs . get ( service_name) ,
457
+ )
458
+ . and_then ( |config| config. shaping . experimental_enable_http2 )
459
+ . unwrap_or ( true )
459
460
}
460
461
}
461
462
@@ -692,6 +693,72 @@ mod test {
692
693
) ;
693
694
}
694
695
696
+ #[ test]
697
+ fn test_merge_http2_all ( ) {
698
+ let config = serde_yaml:: from_str :: < Config > (
699
+ r#"
700
+ all:
701
+ experimental_enable_http2: false
702
+ subgraphs:
703
+ products:
704
+ experimental_enable_http2: true
705
+ reviews:
706
+ experimental_enable_http2: false
707
+ router:
708
+ timeout: 65s
709
+ "# ,
710
+ )
711
+ . unwrap ( ) ;
712
+
713
+ assert ! ( TrafficShaping :: merge_config(
714
+ config. all. as_ref( ) ,
715
+ config. subgraphs. get( "products" )
716
+ )
717
+ . unwrap( )
718
+ . shaping
719
+ . experimental_enable_http2
720
+ . unwrap( ) ) ;
721
+ assert ! ( !TrafficShaping :: merge_config(
722
+ config. all. as_ref( ) ,
723
+ config. subgraphs. get( "reviews" )
724
+ )
725
+ . unwrap( )
726
+ . shaping
727
+ . experimental_enable_http2
728
+ . unwrap( ) ) ;
729
+ assert ! ( !TrafficShaping :: merge_config( config. all. as_ref( ) , None )
730
+ . unwrap( )
731
+ . shaping
732
+ . experimental_enable_http2
733
+ . unwrap( ) ) ;
734
+ }
735
+
736
+ #[ tokio:: test]
737
+ async fn test_enable_subgraph_http2 ( ) {
738
+ let config = serde_yaml:: from_str :: < Config > (
739
+ r#"
740
+ all:
741
+ experimental_enable_http2: false
742
+ subgraphs:
743
+ products:
744
+ experimental_enable_http2: true
745
+ reviews:
746
+ experimental_enable_http2: false
747
+ router:
748
+ timeout: 65s
749
+ "# ,
750
+ )
751
+ . unwrap ( ) ;
752
+
753
+ let shaping_config = TrafficShaping :: new ( PluginInit :: new ( config, Default :: default ( ) ) )
754
+ . await
755
+ . unwrap ( ) ;
756
+
757
+ assert ! ( shaping_config. enable_subgraph_http2( "products" ) ) ;
758
+ assert ! ( !shaping_config. enable_subgraph_http2( "reviews" ) ) ;
759
+ assert ! ( !shaping_config. enable_subgraph_http2( "this_doesnt_exist" ) ) ;
760
+ }
761
+
695
762
#[ tokio:: test( flavor = "multi_thread" ) ]
696
763
async fn it_rate_limit_subgraph_requests ( ) {
697
764
let config = serde_yaml:: from_str :: < serde_json:: Value > (
0 commit comments