-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(graph-gateway): use graphql-http crate client
- Loading branch information
Showing
12 changed files
with
207 additions
and
174 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
mod graphql; | ||
pub mod cost_models; | ||
pub mod indexing_statuses; | ||
pub mod public_poi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub use query::*; | ||
|
||
pub mod client; | ||
mod query; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use graphql_http::http_client::ReqwestExt; | ||
use toolshed::url::Url; | ||
|
||
use crate::indexers_status::cost_models::query; | ||
|
||
pub async fn send_cost_model_query( | ||
client: reqwest::Client, | ||
status_url: Url, | ||
query: query::CostModelQuery, | ||
) -> anyhow::Result<query::CostModelResponse> { | ||
let res = client.post(status_url.0).send_graphql(query).await; | ||
match res { | ||
Ok(res) => Ok(res?), | ||
Err(e) => Err(anyhow::anyhow!("Error sending cost model query: {}", e)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use graphql_http::graphql::{Document, IntoDocument, IntoDocumentWithVariables}; | ||
use indoc::indoc; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::{serde_as, DisplayFromStr}; | ||
use toolshed::thegraph::DeploymentId; | ||
|
||
pub(super) const COST_MODEL_QUERY_DOCUMENT: &str = indoc! { | ||
r#"query ($deployments: [String!]!) { | ||
costModels(deployments: $deployments) { | ||
deployment | ||
model | ||
variables | ||
} | ||
}"# | ||
}; | ||
|
||
#[serde_as] | ||
#[derive(Clone, Debug, Serialize)] | ||
pub struct CostModelQuery { | ||
#[serde_as(as = "Vec<DisplayFromStr>")] | ||
pub deployments: Vec<DeploymentId>, | ||
} | ||
|
||
impl IntoDocumentWithVariables for CostModelQuery { | ||
type Variables = Self; | ||
|
||
fn into_document_with_variables(self) -> (Document, Self::Variables) { | ||
(COST_MODEL_QUERY_DOCUMENT.into_document(), self) | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CostModelResponse { | ||
pub cost_models: Vec<CostModelSourceResponse>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct CostModelSourceResponse { | ||
pub deployment: DeploymentId, | ||
pub model: String, | ||
pub variables: Option<String>, | ||
} |
This file was deleted.
Oops, something went wrong.
14 changes: 12 additions & 2 deletions
14
graph-gateway/src/indexers_status/indexing_statuses/client.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
use graphql_http::http_client::ReqwestExt; | ||
use toolshed::url::Url; | ||
|
||
use crate::indexers_status::graphql; | ||
use crate::indexers_status::indexing_statuses::query; | ||
|
||
pub async fn send_indexing_statuses_query( | ||
client: reqwest::Client, | ||
status_url: Url, | ||
) -> anyhow::Result<query::IndexingStatusesResponse> { | ||
graphql::send_graphql_query(&client, status_url, query::IndexingStatusesQuery).await | ||
let res = client | ||
.post(status_url.0) | ||
.send_graphql(query::INDEXING_STATUSES_QUERY_DOCUMENT) | ||
.await; | ||
match res { | ||
Ok(res) => Ok(res?), | ||
Err(e) => Err(anyhow::anyhow!( | ||
"Error sending indexing statuses query: {}", | ||
e | ||
)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.