@@ -8,7 +8,6 @@ use graphql::http::Response;
88use reqwest:: { header, Client , Url } ;
99use serde:: de:: Deserialize ;
1010use serde_json:: Value ;
11- use toolshed:: thegraph:: DeploymentId ;
1211
1312/// Network subgraph query wrapper
1413///
@@ -20,48 +19,32 @@ pub struct SubgraphClient {
2019}
2120
2221impl SubgraphClient {
23- pub fn new (
24- graph_node_query_endpoint : Option < & str > ,
25- deployment : Option < & DeploymentId > ,
26- subgraph_url : & str ,
27- ) -> Result < Self , anyhow:: Error > {
28- // TODO: Check indexing status of the local subgraph deployment
29- // if the deployment is healthy and synced, use local_subgraoh_endpoint
30- let _local_subgraph_endpoint = match ( graph_node_query_endpoint, deployment) {
31- ( Some ( endpoint) , Some ( id) ) => Some ( Self :: local_deployment_endpoint ( endpoint, id) ?) ,
32- _ => None ,
33- } ;
34-
35- let subgraph_url = Url :: parse ( subgraph_url)
36- . map_err ( |e| anyhow ! ( "Could not parse subgraph url `{}`: {}" , subgraph_url, e) ) ?;
22+ pub fn new ( name : & str , query_url : & str ) -> Result < Self , anyhow:: Error > {
23+ let query_url = Url :: parse ( query_url) . map_err ( |e| {
24+ anyhow ! (
25+ "Could not parse `{}` subgraph query URL `{}`: {}" ,
26+ name,
27+ query_url,
28+ e
29+ )
30+ } ) ?;
3731
3832 let client = reqwest:: Client :: builder ( )
3933 . user_agent ( "indexer-common" )
4034 . build ( )
41- . expect ( "Could not build a client for the Graph Node query endpoint" ) ;
35+ . map_err ( |err| {
36+ anyhow ! (
37+ "Could not build a client for `{name}` subgraph query URL `{query_url}`: {err}"
38+ )
39+ } )
40+ . expect ( "Building subgraph client" ) ;
4241
4342 Ok ( Self {
4443 client,
45- subgraph_url : Arc :: new ( subgraph_url ) ,
44+ subgraph_url : Arc :: new ( query_url ) ,
4645 } )
4746 }
4847
49- pub fn local_deployment_endpoint (
50- graph_node_query_endpoint : & str ,
51- deployment : & DeploymentId ,
52- ) -> Result < Url , anyhow:: Error > {
53- Url :: parse ( graph_node_query_endpoint)
54- . and_then ( |u| u. join ( "/subgraphs/id/" ) )
55- . and_then ( |u| u. join ( & deployment. to_string ( ) ) )
56- . map_err ( |e| {
57- anyhow ! (
58- "Could not parse Graph Node query endpoint for subgraph deployment `{}`: {}" ,
59- deployment,
60- e
61- )
62- } )
63- }
64-
6548 pub async fn query < T : for < ' de > Deserialize < ' de > > (
6649 & self ,
6750 body : & Value ,
@@ -117,12 +100,7 @@ mod test {
117100 }
118101
119102 fn network_subgraph_client ( ) -> SubgraphClient {
120- SubgraphClient :: new (
121- Some ( GRAPH_NODE_STATUS_ENDPOINT ) ,
122- Some ( & test_vectors:: NETWORK_SUBGRAPH_DEPLOYMENT ) ,
123- NETWORK_SUBGRAPH_URL ,
124- )
125- . unwrap ( )
103+ SubgraphClient :: new ( "network-subgraph" , NETWORK_SUBGRAPH_URL ) . unwrap ( )
126104 }
127105
128106 #[ tokio:: test]
0 commit comments