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

@@ -247,7 +247,7 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
return $(output_type) {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}
};
}
@@ -273,15 +273,13 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To
return vec![$(output_type) {
proc: self.proc.clone(),
selection: query,
conn: self.conn.clone(),
graphql_client: self.graphql_client.clone(),
}]
};
}
let graphql_client = rust::import("crate::client", "graphql_client");
quote! {
query.execute(&$graphql_client(&self.conn)).await
query.execute(self.graphql_client.clone()).await
}
}

View File

@@ -12,15 +12,15 @@ use crate::utility::OptionExt;
pub fn render_object(funcs: &CommonFunctions, t: &FullType) -> eyre::Result<rust::Tokens> {
let selection = rust::import("crate::querybuilder", "Selection");
let child = rust::import("tokio::process", "Child");
let conn = rust::import("dagger_core::connect_params", "ConnectParams");
let graphql_client = rust::import("dagger_core::graphql_client", "DynGraphQLClient");
let arc = rust::import("std::sync", "Arc");
Ok(quote! {
#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct $(t.name.pipe(|s| format_name(s))) {
pub proc: $arc<$child>,
pub selection: $selection,
pub conn: $conn,
pub graphql_client: $graphql_client
}
$(t.fields.pipe(|f| render_optional_args(funcs, f)))