diff --git a/gql/gva_queries.gql b/gql/gva_queries.gql index 2c1ae9f68672e71584cf71d8da4f259d86e3d0dd..52d8aba3d81698e18161e06f0c87726a29fd6226 100644 --- a/gql/gva_queries.gql +++ b/gql/gva_queries.gql @@ -1,4 +1,4 @@ -query BalanceQuery($script: String!, $withUd: Boolean!) { +query Balance($script: String!, $withUd: Boolean!) { balance(script: $script) { amount } @@ -7,7 +7,7 @@ query BalanceQuery($script: String!, $withUd: Boolean!) { } } -query CurrentUdQuery { +query CurrentUd { currentUd { amount } diff --git a/src/commands.rs b/src/commands.rs index d03ff599a1b826637a7e5384e47fbb7a3e8cd607..ab1dfd4f5c4227a8b3f2217c68d8699ea562d80b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -33,17 +33,17 @@ pub(crate) fn balance<W: Write>( pubkey_or_script: &str, ud_unit: bool, ) -> anyhow::Result<()> { - let request_body = BalanceQuery::build_query(balance_query::Variables { + let request_body = Balance::build_query(balance::Variables { script: pubkey_or_script.to_owned(), with_ud: ud_unit, }); - let balance_query::ResponseData { - balance: balance_query::BalanceQueryBalance { amount }, + let balance::ResponseData { + balance: balance::BalanceBalance { amount }, current_ud: current_ud_opt, } = client.send_gql_query(&request_body)?; - if let Some(balance_query::BalanceQueryCurrentUd { amount: ud_amount }) = current_ud_opt { + if let Some(balance::BalanceCurrentUd { amount: ud_amount }) = current_ud_opt { writeln!( out, "The balance of account '{}' is {:.2} UDĞ1 !", @@ -63,10 +63,10 @@ pub(crate) fn balance<W: Write>( } pub(crate) fn current_ud<W: Write>(client: &Client, out: &mut W) -> anyhow::Result<()> { - let request_body = CurrentUdQuery::build_query(current_ud_query::Variables); + let request_body = CurrentUd::build_query(current_ud::Variables); - if let current_ud_query::ResponseData { - current_ud: Some(current_ud_query::CurrentUdQueryCurrentUd { amount }), + if let current_ud::ResponseData { + current_ud: Some(current_ud::CurrentUdCurrentUd { amount }), } = client.send_gql_query(&request_body)? { let int_part = amount / 100; @@ -91,10 +91,10 @@ mod tests { fn test_balance() -> anyhow::Result<()> { let mut client = Client::default(); client - .expect_send_gql_query::<graphql_client::QueryBody<balance_query::Variables>, _>() + .expect_send_gql_query::<graphql_client::QueryBody<balance::Variables>, _>() .returning(|_| { - Ok(balance_query::ResponseData { - balance: balance_query::BalanceQueryBalance { amount: 2_046 }, + Ok(balance::ResponseData { + balance: balance::BalanceBalance { amount: 2_046 }, current_ud: None, }) }); @@ -111,11 +111,11 @@ mod tests { fn test_balance_with_ud_unit() -> anyhow::Result<()> { let mut client = Client::default(); client - .expect_send_gql_query::<graphql_client::QueryBody<balance_query::Variables>, _>() + .expect_send_gql_query::<graphql_client::QueryBody<balance::Variables>, _>() .returning(|_| { - Ok(balance_query::ResponseData { - balance: balance_query::BalanceQueryBalance { amount: 2_046 }, - current_ud: Some(balance_query::BalanceQueryCurrentUd { amount: 1_023 }), + Ok(balance::ResponseData { + balance: balance::BalanceBalance { amount: 2_046 }, + current_ud: Some(balance::BalanceCurrentUd { amount: 1_023 }), }) }); let mut out = Vec::new(); @@ -131,10 +131,10 @@ mod tests { fn test_current_ud() -> anyhow::Result<()> { let mut client = Client::default(); client - .expect_send_gql_query::<graphql_client::QueryBody<current_ud_query::Variables>, _>() + .expect_send_gql_query::<graphql_client::QueryBody<current_ud::Variables>, _>() .returning(|_| { - Ok(current_ud_query::ResponseData { - current_ud: Some(current_ud_query::CurrentUdQueryCurrentUd { amount: 1_023 }), + Ok(current_ud::ResponseData { + current_ud: Some(current_ud::CurrentUdCurrentUd { amount: 1_023 }), }) }); let mut out = Vec::new(); diff --git a/src/main.rs b/src/main.rs index b664c1d3ac6a5342e66895f36145748afdd69a42..4b7e8e9757b9cbe0b871c0e6d1d5962f6801384f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,11 +43,11 @@ const DEFAULT_GVA_SERVER: &str = "https://g1.librelois.fr/gva"; #[derive(Debug, Clone, Copy, GraphQLQuery)] #[graphql(schema_path = "gql/gva_schema.gql", query_path = "gql/gva_queries.gql")] -pub struct BalanceQuery; +pub struct Balance; #[derive(Debug, Clone, Copy, GraphQLQuery)] #[graphql(schema_path = "gql/gva_schema.gql", query_path = "gql/gva_queries.gql")] -pub struct CurrentUdQuery; +pub struct CurrentUd; #[derive(StructOpt)] #[structopt(name = "rust-gva-client", about = "Client use GVA API of Duniter.")]