From 6d053da9f4b8d6e34714d6ff32f52cfb67c2582e Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 19 Mar 2023 00:50:21 +0100 Subject: [PATCH] feat: fix extract --- crates/dagger-codegen/src/rust/functions.rs | 4 +- crates/dagger-core/src/graphql_client.rs | 24 +-- crates/dagger-sdk/src/gen.rs | 214 +++++--------------- 3 files changed, 60 insertions(+), 182 deletions(-) diff --git a/crates/dagger-codegen/src/rust/functions.rs b/crates/dagger-codegen/src/rust/functions.rs index f9183ff..7ce020f 100644 --- a/crates/dagger-codegen/src/rust/functions.rs +++ b/crates/dagger-codegen/src/rust/functions.rs @@ -278,10 +278,8 @@ fn render_execution(funcs: &CommonFunctions, field: &FullTypeFields) -> rust::To }; } - let graphql_client = rust::import("crate::client", "graphql_client"); - quote! { - query.execute(&$graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } } diff --git a/crates/dagger-core/src/graphql_client.rs b/crates/dagger-core/src/graphql_client.rs index ee0ce37..77548a2 100644 --- a/crates/dagger-core/src/graphql_client.rs +++ b/crates/dagger-core/src/graphql_client.rs @@ -1,19 +1,16 @@ use std::collections::HashMap; -use std::future::Future; -use std::pin::Pin; use std::sync::Arc; +use async_trait::async_trait; use base64::engine::general_purpose; use base64::Engine; use gql_client::ClientConfig; -use serde::Deserialize; use crate::connect_params::ConnectParams; +#[async_trait] pub trait GraphQLClient { - fn query(&self, query: String) -> Pin>>>> - where - K: for<'de> Deserialize<'de>; + async fn query(&self, query: &str) -> eyre::Result>; } pub type DynGraphQLClient = Arc; @@ -41,14 +38,15 @@ impl DefaultGraphQLClient { } } +#[async_trait] impl GraphQLClient for DefaultGraphQLClient { - fn query(&self, query: String) -> Pin>>>> - where - Self: Sized, - K: for<'de> Deserialize<'de>, - { - let res = self.client.query::(&query); + async fn query(&self, query: &str) -> eyre::Result> { + let res: Option = self + .client + .query(&query) + .await + .map_err(|r| eyre::anyhow!(r.to_string()))?; - return Box::pin(res); + return Ok(res); } } diff --git a/crates/dagger-sdk/src/gen.rs b/crates/dagger-sdk/src/gen.rs index d68348d..22c9ff4 100644 --- a/crates/dagger-sdk/src/gen.rs +++ b/crates/dagger-sdk/src/gen.rs @@ -1,6 +1,4 @@ -use crate::client::graphql_client; use crate::querybuilder::Selection; -use dagger_core::connect_params::ConnectParams; use dagger_core::graphql_client::DynGraphQLClient; use derive_builder::Builder; use serde::{Deserialize, Serialize}; @@ -119,7 +117,6 @@ pub struct PipelineLabel { pub struct CacheVolume { pub proc: Arc, pub selection: Selection, - pub conn: ConnectParams, pub graphql_client: DynGraphQLClient, } @@ -127,14 +124,13 @@ impl CacheVolume { pub async fn id(&self) -> eyre::Result { let query = self.selection.select("id"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } } #[derive(Clone)] pub struct Container { pub proc: Arc, pub selection: Selection, - pub conn: ConnectParams, pub graphql_client: DynGraphQLClient, } @@ -298,7 +294,6 @@ impl Container { return Container { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -326,7 +321,6 @@ impl Container { return Container { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -334,7 +328,7 @@ impl Container { pub async fn default_args(&self) -> eyre::Result> { let query = self.selection.select("defaultArgs"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves a directory at the given path. /// Mounts are included. @@ -350,7 +344,6 @@ impl Container { return Directory { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -365,7 +358,7 @@ impl Container { pub async fn endpoint(&self) -> eyre::Result { let query = self.selection.select("endpoint"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves an endpoint that clients can use to reach this container. @@ -386,13 +379,13 @@ impl Container { query = query.arg("scheme", scheme); } - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves entrypoint to be prepended to the arguments of all commands. pub async fn entrypoint(&self) -> eyre::Result> { let query = self.selection.select("entrypoint"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves the value of the specified environment variable. /// @@ -404,7 +397,7 @@ impl Container { query = query.arg("name", name.into()); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves the list of environment variables passed to commands. pub fn env_variables(&self) -> Vec { @@ -413,7 +406,6 @@ impl Container { return vec![EnvVariable { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }]; } @@ -428,7 +420,6 @@ impl Container { return Container { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -463,7 +454,6 @@ impl Container { return Container { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -472,7 +462,7 @@ impl Container { pub async fn exit_code(&self) -> eyre::Result { let query = self.selection.select("exitCode"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Writes the container as an OCI tarball to the destination file path on the host for the specified platform variants. /// Return true on success. @@ -488,7 +478,7 @@ impl Container { query = query.arg("path", path.into()); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Writes the container as an OCI tarball to the destination file path on the host for the specified platform variants. @@ -512,7 +502,7 @@ impl Container { query = query.arg("platformVariants", platform_variants); } - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves the list of exposed ports. /// Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable. @@ -522,7 +512,6 @@ impl Container { return vec![Port { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }]; } @@ -540,7 +529,6 @@ impl Container { return File { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -559,7 +547,6 @@ impl Container { return Container { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -570,7 +557,6 @@ impl Container { return Directory { proc: self.proc.clone(), selection: query, - conn: self.conn.clone(), graphql_client: self.graphql_client.clone(), }; } @@ -579,19 +565,19 @@ impl Container { pub async fn hostname(&self) -> eyre::Result { let query = self.selection.select("hostname"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// A unique identifier for this container. pub async fn id(&self) -> eyre::Result { let query = self.selection.select("id"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// The unique image reference which can only be retrieved immediately after the 'Container.From' call. pub async fn image_ref(&self) -> eyre::Result { let query = self.selection.select("imageRef"); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves the value of the specified label. pub async fn label(&self, name: impl Into) -> eyre::Result { @@ -599,7 +585,7 @@ impl Container { query = query.arg("name", name.into()); - query.execute(&graphql_client(&self.conn)).await + query.execute(self.graphql_client.clone()).await } /// Retrieves the list of labels passed to container. pub fn labels(&self) -> Vec