feat: fix extract

This commit is contained in:
Kasper Juul Hermansen 2023-03-19 00:50:21 +01:00
parent ab6141ffb4
commit 6d053da9f4
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
3 changed files with 60 additions and 182 deletions

View File

@ -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
}
}

View File

@ -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<K>(&self, query: String) -> Pin<Box<dyn Future<Output = eyre::Result<Option<K>>>>>
where
K: for<'de> Deserialize<'de>;
async fn query(&self, query: &str) -> eyre::Result<Option<serde_json::Value>>;
}
pub type DynGraphQLClient = Arc<dyn GraphQLClient + Send + Sync>;
@ -41,14 +38,15 @@ impl DefaultGraphQLClient {
}
}
#[async_trait]
impl GraphQLClient for DefaultGraphQLClient {
fn query<K>(&self, query: String) -> Pin<Box<dyn Future<Output = eyre::Result<Option<K>>>>>
where
Self: Sized,
K: for<'de> Deserialize<'de>,
{
let res = self.client.query::<K>(&query);
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 Box::pin(res);
return Ok(res);
}
}

File diff suppressed because it is too large Load Diff