mirror of
https://github.com/kjuulh/dagger-rs.git
synced 2025-07-26 03:19:21 +02:00
fix: serialization of enum args for graphql (#34)
This commit is contained in:
@@ -955,7 +955,7 @@ impl Container {
|
||||
|
||||
query = query.arg("port", port);
|
||||
if let Some(protocol) = opts.protocol {
|
||||
query = query.arg("protocol", protocol);
|
||||
query = query.arg_enum("protocol", protocol);
|
||||
}
|
||||
if let Some(description) = opts.description {
|
||||
query = query.arg("description", description);
|
||||
@@ -1085,7 +1085,7 @@ impl Container {
|
||||
query = query.arg("source", source);
|
||||
}
|
||||
if let Some(sharing) = opts.sharing {
|
||||
query = query.arg("sharing", sharing);
|
||||
query = query.arg_enum("sharing", sharing);
|
||||
}
|
||||
|
||||
return Container {
|
||||
@@ -1395,7 +1395,7 @@ impl Container {
|
||||
|
||||
query = query.arg("port", port);
|
||||
if let Some(protocol) = opts.protocol {
|
||||
query = query.arg("protocol", protocol);
|
||||
query = query.arg_enum("protocol", protocol);
|
||||
}
|
||||
|
||||
return Container {
|
||||
@@ -2848,9 +2848,9 @@ impl Socket {
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
pub enum CacheSharingMode {
|
||||
LOCKED,
|
||||
SHARED,
|
||||
PRIVATE,
|
||||
LOCKED,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
pub enum NetworkProtocol {
|
||||
|
@@ -68,6 +68,32 @@ impl Selection {
|
||||
s
|
||||
}
|
||||
|
||||
pub fn arg_enum<S>(&self, name: &str, value: S) -> Selection
|
||||
where
|
||||
S: Serialize,
|
||||
{
|
||||
let mut s = self.clone();
|
||||
|
||||
let val = serde_json::to_string(&value).unwrap();
|
||||
let val = val[1..val.len() - 1].to_string();
|
||||
|
||||
println!("test");
|
||||
println!("{}", val);
|
||||
|
||||
match s.args.as_mut() {
|
||||
Some(args) => {
|
||||
let _ = args.insert(name.to_string(), val);
|
||||
}
|
||||
None => {
|
||||
let mut hm = HashMap::new();
|
||||
let _ = hm.insert(name.to_string(), val);
|
||||
s.args = Some(hm);
|
||||
}
|
||||
}
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
pub fn build(&self) -> eyre::Result<String> {
|
||||
let mut fields = vec!["query".to_string()];
|
||||
|
||||
@@ -76,7 +102,7 @@ impl Selection {
|
||||
if let Some(args) = sel.args {
|
||||
let actualargs = args
|
||||
.iter()
|
||||
.map(|(name, arg)| format!("{name}:{arg}"))
|
||||
.map(|(name, arg)| format!("{name}:{}", arg.as_str()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
query = query.add(&format!("({})", actualargs.join(", ")));
|
||||
@@ -99,6 +125,9 @@ impl Selection {
|
||||
{
|
||||
let query = self.build()?;
|
||||
|
||||
let qbs = query.as_str();
|
||||
println!("{}", qbs);
|
||||
|
||||
let resp: Option<serde_json::Value> = match gql_client.query(&query).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => eyre::bail!(e),
|
||||
|
Reference in New Issue
Block a user