This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This extracts the client (strategy pattern), this is so that it is will be possible to test the actual querier, without hitting / requiring the dagger-engine running.
- Loading branch information
Showing
10 changed files
with
289 additions
and
232 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
use base64::engine::general_purpose; | ||
use base64::Engine; | ||
use gql_client::ClientConfig; | ||
|
||
use crate::connect_params::ConnectParams; | ||
|
||
#[async_trait] | ||
pub trait GraphQLClient { | ||
async fn query(&self, query: &str) -> eyre::Result<Option<serde_json::Value>>; | ||
} | ||
|
||
pub type DynGraphQLClient = Arc<dyn GraphQLClient + Send + Sync>; | ||
|
||
#[derive(Debug)] | ||
pub struct DefaultGraphQLClient { | ||
client: gql_client::Client, | ||
} | ||
|
||
impl DefaultGraphQLClient { | ||
pub fn new(conn: &ConnectParams) -> Self { | ||
let token = general_purpose::URL_SAFE.encode(format!("{}:", conn.session_token)); | ||
|
||
let mut headers = HashMap::new(); | ||
headers.insert("Authorization".to_string(), format!("Basic {}", token)); | ||
|
||
Self { | ||
client: gql_client::Client::new_with_config(ClientConfig { | ||
endpoint: conn.url(), | ||
timeout: Some(1000), | ||
headers: Some(headers), | ||
proxy: None, | ||
}), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl GraphQLClient for DefaultGraphQLClient { | ||
async fn query(&self, query: &str) -> eyre::Result<Option<serde_json::Value>> { | ||
let res: Option<serde_json::Value> = self | ||
.client | ||
.query(&query) | ||
.await | ||
.map_err(|r| eyre::anyhow!(r.to_string()))?; | ||
|
||
return Ok(res); | ||
} | ||
} |
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
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.