@@ -41,13 +41,15 @@ impl DeploymentDetails {
4141}
4242
4343struct DeploymentClient {
44+ pub http_client : reqwest:: Client ,
4445 pub status : Option < Eventual < DeploymentStatus > > ,
4546 pub query_url : Url ,
4647}
4748
4849impl DeploymentClient {
49- pub fn new ( details : DeploymentDetails ) -> Self {
50+ pub fn new ( http_client : reqwest :: Client , details : DeploymentDetails ) -> Self {
5051 Self {
52+ http_client,
5153 status : details
5254 . deployment
5355 . zip ( details. status_url )
@@ -71,7 +73,8 @@ impl DeploymentClient {
7173 }
7274 }
7375
74- Ok ( reqwest:: Client :: new ( )
76+ Ok ( self
77+ . http_client
7578 . post ( self . query_url . as_ref ( ) )
7679 . json ( body)
7780 . header ( header:: USER_AGENT , "indexer-common" )
@@ -92,16 +95,14 @@ pub struct SubgraphClient {
9295
9396impl SubgraphClient {
9497 pub fn new (
98+ http_client : reqwest:: Client ,
9599 local_deployment : Option < DeploymentDetails > ,
96100 remote_deployment : DeploymentDetails ,
97- ) -> Result < Self , anyhow:: Error > {
98- let local_client = local_deployment. map ( DeploymentClient :: new) ;
99- let remote_client = DeploymentClient :: new ( remote_deployment) ;
100-
101- Ok ( Self {
102- local_client,
103- remote_client,
104- } )
101+ ) -> Self {
102+ Self {
103+ local_client : local_deployment. map ( |d| DeploymentClient :: new ( http_client. clone ( ) , d) ) ,
104+ remote_client : DeploymentClient :: new ( http_client, remote_deployment) ,
105+ }
105106 }
106107
107108 pub async fn query < T : for < ' de > Deserialize < ' de > > (
@@ -173,10 +174,10 @@ mod test {
173174
174175 fn network_subgraph_client ( ) -> SubgraphClient {
175176 SubgraphClient :: new (
177+ reqwest:: Client :: new ( ) ,
176178 None ,
177179 DeploymentDetails :: for_query_url ( NETWORK_SUBGRAPH_URL ) . unwrap ( ) ,
178180 )
179- . unwrap ( )
180181 }
181182
182183 #[ tokio:: test]
@@ -253,15 +254,15 @@ mod test {
253254
254255 // Create the subgraph client
255256 let client = SubgraphClient :: new (
257+ reqwest:: Client :: new ( ) ,
256258 Some ( DeploymentDetails :: for_graph_node ( & mock_server_local. uri ( ) , deployment) . unwrap ( ) ) ,
257259 DeploymentDetails :: for_query_url ( & format ! (
258260 "{}/subgraphs/id/{}" ,
259261 mock_server_remote. uri( ) ,
260262 deployment
261263 ) )
262264 . unwrap ( ) ,
263- )
264- . unwrap ( ) ;
265+ ) ;
265266
266267 // Query the subgraph
267268 let response: Response < Value > = client
@@ -325,15 +326,15 @@ mod test {
325326
326327 // Create the subgraph client
327328 let client = SubgraphClient :: new (
329+ reqwest:: Client :: new ( ) ,
328330 Some ( DeploymentDetails :: for_graph_node ( & mock_server_local. uri ( ) , deployment) . unwrap ( ) ) ,
329331 DeploymentDetails :: for_query_url ( & format ! (
330332 "{}/subgraphs/id/{}" ,
331333 mock_server_remote. uri( ) ,
332334 deployment
333335 ) )
334336 . unwrap ( ) ,
335- )
336- . unwrap ( ) ;
337+ ) ;
337338
338339 // Query the subgraph
339340 let response: Response < Value > = client
@@ -397,15 +398,15 @@ mod test {
397398
398399 // Create the subgraph client
399400 let client = SubgraphClient :: new (
401+ reqwest:: Client :: new ( ) ,
400402 Some ( DeploymentDetails :: for_graph_node ( & mock_server_local. uri ( ) , deployment) . unwrap ( ) ) ,
401403 DeploymentDetails :: for_query_url ( & format ! (
402404 "{}/subgraphs/id/{}" ,
403405 mock_server_remote. uri( ) ,
404406 deployment
405407 ) )
406408 . unwrap ( ) ,
407- )
408- . unwrap ( ) ;
409+ ) ;
409410
410411 // Query the subgraph
411412 let response: Response < Value > = client
0 commit comments