@@ -41,24 +41,37 @@ impl<L: LinkResolver> SubgraphProvider<L> {
4141 name : String ,
4242 id : String ,
4343 ) -> impl Future < Item = ( ) , Error = SubgraphProviderError > + Send + ' static {
44- let graphql_remove_sink = self . schema_event_sink . clone ( ) ;
45- let host_remove_sink = self . event_sink . clone ( ) ;
46- graphql_remove_sink
44+ self . schema_event_sink
45+ . clone ( )
4746 . send ( SchemaEvent :: SchemaRemoved ( name, id. clone ( ) ) )
48- . map_err ( |e| panic ! ( "Failed to forward schema removal: {}" , e) )
47+ . map_err ( |e| panic ! ( "failed to forward schema removal: {}" , e) )
4948 . map ( |_| ( ) )
5049 . join (
51- host_remove_sink
50+ self . event_sink
51+ . clone ( )
5252 . send ( SubgraphProviderEvent :: SubgraphRemoved ( id) )
5353 . map ( |_| ( ) )
54- . map_err ( |e| panic ! ( "Failed to forward subgraph removal: {}" , e) ) ,
54+ . map_err ( |e| panic ! ( "failed to forward subgraph removal: {}" , e) ) ,
5555 ) . map ( |_| ( ) )
5656 }
57+
58+ /// Clones but forcing receivers to `None`.
59+ fn clone ( & self ) -> Self {
60+ SubgraphProvider {
61+ _logger : self . _logger . clone ( ) ,
62+ event_stream : None ,
63+ event_sink : self . event_sink . clone ( ) ,
64+ schema_event_stream : None ,
65+ schema_event_sink : self . schema_event_sink . clone ( ) ,
66+ resolver : self . resolver . clone ( ) ,
67+ subgraphs : self . subgraphs . clone ( ) ,
68+ }
69+ }
5770}
5871
5972impl < L : LinkResolver > SubgraphProviderTrait for SubgraphProvider < L > {
6073 fn deploy (
61- arc_self : & Arc < Self > ,
74+ & self ,
6275 name : String ,
6376 link : String ,
6477 ) -> Box < Future < Item = ( ) , Error = SubgraphProviderError > + Send + ' static > {
@@ -70,9 +83,9 @@ impl<L: LinkResolver> SubgraphProviderTrait for SubgraphProvider<L> {
7083 return Box :: new ( Err ( SubgraphProviderError :: InvalidName ( name) ) . into_future ( ) ) ;
7184 }
7285
73- let arc_self = arc_self . clone ( ) ;
86+ let self_clone = self . clone ( ) ;
7487 Box :: new (
75- SubgraphManifest :: resolve ( name. clone ( ) , Link { link } , arc_self . resolver . clone ( ) )
88+ SubgraphManifest :: resolve ( name. clone ( ) , Link { link } , self_clone . resolver . clone ( ) )
7689 . map_err ( SubgraphProviderError :: ResolveError )
7790 . and_then (
7891 // Validate the subgraph schema before deploying the subgraph
@@ -85,38 +98,33 @@ impl<L: LinkResolver> SubgraphProviderTrait for SubgraphProvider<L> {
8598 . schema
8699 . add_subgraph_id_directives ( subgraph. id . clone ( ) ) ;
87100
88- let old_id = arc_self
101+ let old_id = self_clone
89102 . subgraphs
90103 . lock ( )
91104 . unwrap ( )
92105 . insert ( name. clone ( ) , subgraph. id . clone ( ) ) ;
93106
94107 // If a subgraph is being updated, remove the old subgraph.
95- let removal_arc_self = arc_self. clone ( ) ;
96108 if let Some ( id) = old_id {
97- Box :: new (
98- arc_self
99- . send_remove_events ( name, id)
100- . map ( move |_| ( removal_arc_self, subgraph) ) ,
101- )
102- as Box < Future < Item = _ , Error = _ > + Send + ' static >
109+ Box :: new ( self_clone. send_remove_events ( name, id) )
103110 } else {
104- Box :: new ( future:: ok :: < _ , SubgraphProviderError > ( ( arc_self, subgraph) ) )
105- }
106- } ) . and_then ( |( arc_self, subgraph) | {
107- // Push the subgraph and the schema into their streams
108- arc_self
109- . schema_event_sink
110- . clone ( )
111- . send ( SchemaEvent :: SchemaAdded ( subgraph. schema . clone ( ) ) )
112- . map_err ( |e| panic ! ( "Failed to forward subgraph schema: {}" , e) )
113- . join (
114- arc_self
115- . event_sink
116- . clone ( )
117- . send ( SubgraphProviderEvent :: SubgraphAdded ( subgraph) )
118- . map_err ( |e| panic ! ( "Failed to forward subgraph: {}" , e) ) ,
119- ) . map ( |_| ( ) )
111+ Box :: new ( future:: ok ( ( ) ) )
112+ as Box < Future < Item = _ , Error = _ > + Send + ' static >
113+ } . and_then ( move |_| {
114+ // Push the subgraph and the schema into their streams
115+ self_clone
116+ . schema_event_sink
117+ . clone ( )
118+ . send ( SchemaEvent :: SchemaAdded ( subgraph. schema . clone ( ) ) )
119+ . map_err ( |e| panic ! ( "failed to forward subgraph schema: {}" , e) )
120+ . join (
121+ self_clone
122+ . event_sink
123+ . clone ( )
124+ . send ( SubgraphProviderEvent :: SubgraphAdded ( subgraph) )
125+ . map_err ( |e| panic ! ( "failed to forward subgraph: {}" , e) ) ,
126+ ) . map ( |_| ( ) )
127+ } )
120128 } ) ,
121129 )
122130 }
@@ -188,7 +196,7 @@ fn rejects_name_bad_for_urls() {
188196 let logger = slog:: Logger :: root ( slog:: Discard , o ! ( ) ) ;
189197 let provider = Arc :: new ( SubgraphProvider :: new ( logger, Arc :: new ( FakeLinkResolver ) ) ) ;
190198 let bad = "/../funky%2F:9001" . to_owned ( ) ;
191- let result = SubgraphProvider :: deploy ( & provider , bad. clone ( ) , "" . to_owned ( ) ) ;
199+ let result = provider . deploy ( bad. clone ( ) , "" . to_owned ( ) ) ;
192200 match result. wait ( ) {
193201 Err ( SubgraphProviderError :: InvalidName ( name) ) => assert_eq ! ( name, bad) ,
194202 x => panic ! ( "unexpected test result {:?}" , x) ,
0 commit comments