feat: extract client (#48)

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.
This commit is contained in:
2023-03-19 01:01:24 +01:00
committed by GitHub
parent 384294b390
commit 11d20935c6
10 changed files with 289 additions and 232 deletions

View File

@@ -1,12 +1,8 @@
use std::collections::HashMap;
use std::sync::Arc;
use base64::engine::general_purpose;
use base64::Engine;
use gql_client::ClientConfig;
use dagger_core::graphql_client::DefaultGraphQLClient;
use dagger_core::config::Config;
use dagger_core::connect_params::ConnectParams;
use dagger_core::engine::Engine as DaggerEngine;
use crate::gen::Query;
@@ -25,26 +21,12 @@ pub async fn connect_opts(cfg: Config) -> eyre::Result<DaggerConn> {
let (conn, proc) = DaggerEngine::new().start(&cfg).await?;
Ok(Arc::new(Query {
conn,
proc: Arc::new(proc),
selection: query(),
graphql_client: Arc::new(DefaultGraphQLClient::new(&conn)),
}))
}
pub fn graphql_client(conn: &ConnectParams) -> gql_client::Client {
let token = general_purpose::URL_SAFE.encode(format!("{}:", conn.session_token));
let mut headers = HashMap::new();
headers.insert("Authorization".to_string(), format!("Basic {}", token));
gql_client::Client::new_with_config(ClientConfig {
endpoint: conn.url(),
timeout: Some(1000),
headers: Some(headers),
proxy: None,
})
}
// Conn will automatically close on drop of proc
#[cfg(test)]

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
use std::{collections::HashMap, ops::Add, sync::Arc};
use dagger_core::graphql_client::DynGraphQLClient;
use eyre::Context;
use serde::{Deserialize, Serialize};
@@ -116,7 +117,7 @@ impl Selection {
Ok(fields.join("{") + &"}".repeat(fields.len() - 1))
}
pub async fn execute<D>(&self, gql_client: &gql_client::Client) -> eyre::Result<D>
pub async fn execute<D>(&self, gql_client: DynGraphQLClient) -> eyre::Result<D>
where
D: for<'de> Deserialize<'de>,
{