diff --git a/crates/monitor/src/client/subgraph_client.rs b/crates/monitor/src/client/subgraph_client.rs index aa68c6a63..178161fae 100644 --- a/crates/monitor/src/client/subgraph_client.rs +++ b/crates/monitor/src/client/subgraph_client.rs @@ -14,10 +14,10 @@ pub type ResponseResult = Result; #[derive(Debug, Clone)] pub struct DeploymentDetails { - pub deployment: Option, - pub status_url: Option, - pub query_url: Url, - pub query_auth_token: Option, + deployment: Option, + status_url: Option, + query_url: Url, + query_auth_token: Option, } impl DeploymentDetails { @@ -79,6 +79,7 @@ struct DeploymentClient { pub http_client: reqwest::Client, pub status: Option>, pub query_url: Url, + pub query_auth_token: Option, } impl DeploymentClient { @@ -99,6 +100,7 @@ impl DeploymentClient { None => None, }, query_url: details.query_url, + query_auth_token: details.query_auth_token, } } @@ -118,13 +120,17 @@ impl DeploymentClient { } let body = T::build_query(variables); - let reqwest_response = self + let mut req = self .http_client .post(self.query_url.as_ref()) .header(header::USER_AGENT, "indexer-common") - .json(&body) - .send() - .await?; + .json(&body); + + if let Some(token) = self.query_auth_token.as_ref() { + req = req.header(header::AUTHORIZATION, format!("Bearer {}", token)); + } + + let reqwest_response = req.send().await?; let response: graphql_client::Response = reqwest_response.json().await?; // TODO handle partial responses @@ -154,14 +160,18 @@ impl DeploymentClient { } } - Ok(self + let mut req = self .http_client .post(self.query_url.as_ref()) .header(header::USER_AGENT, "indexer-common") .header(header::CONTENT_TYPE, "application/json") - .body(body) - .send() - .await?) + .body(body); + + if let Some(token) = self.query_auth_token.as_ref() { + req = req.header(header::AUTHORIZATION, format!("Bearer {}", token)); + } + + Ok(req.send().await?) } }