From 64ccae3f11dbf3a3cfce29b88967a3a4eb563704 Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Wed, 8 Jul 2020 16:59:32 +0200 Subject: [PATCH] Update async-grapql version Use new OutputJson for VoteOptions Removed unnecessary code --- Cargo.lock | 8 +++--- vit-servicing-station-lib/Cargo.toml | 4 +-- .../src/db/models/vote_options.rs | 4 ++- .../src/v0/endpoints/graphql/schema/funds.rs | 11 +++++++- .../src/v0/endpoints/graphql/schema/mod.rs | 1 - .../v0/endpoints/graphql/schema/proposals.rs | 6 +++-- .../endpoints/graphql/schema/vote_options.rs | 25 ------------------- 7 files changed, 23 insertions(+), 36 deletions(-) delete mode 100644 vit-servicing-station-lib/src/v0/endpoints/graphql/schema/vote_options.rs diff --git a/Cargo.lock b/Cargo.lock index f17c59a4..60b520f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,9 +122,9 @@ dependencies = [ [[package]] name = "async-graphql" -version = "1.16.4" +version = "1.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdda3fe2d072d88f275d9c115ed36e4f8ca81f0f0b0c625e8a4976f927d3e4bc" +checksum = "9858525cbab952ee271bd7c914669892a0fec19bac70207b0bb44a2647c9ef3f" dependencies = [ "Inflector", "anyhow", @@ -192,9 +192,9 @@ dependencies = [ [[package]] name = "async-graphql-warp" -version = "1.16.4" +version = "1.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f444c6f6fa5803990c45735e314419a1a608ea2fbd9c131c2d9e58667ea044" +checksum = "a5c0565520a271f754cef2597ccc3b73d2ee62b0ffd7aee980905ac85d6f77ee" dependencies = [ "anyhow", "async-graphql", diff --git a/vit-servicing-station-lib/Cargo.toml b/vit-servicing-station-lib/Cargo.toml index 74b25328..3b1e3213 100644 --- a/vit-servicing-station-lib/Cargo.toml +++ b/vit-servicing-station-lib/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -async-graphql = "1.16.2" -async-graphql-warp = "1.16.2" +async-graphql = "1.16.8" +async-graphql-warp = "1.16.6" async-trait = "0.1.33" base64 = "0.12.1" chrono = { version = "0.4", features = ["serde"] } diff --git a/vit-servicing-station-lib/src/db/models/vote_options.rs b/vit-servicing-station-lib/src/db/models/vote_options.rs index 0d3946e1..aed58f7b 100644 --- a/vit-servicing-station-lib/src/db/models/vote_options.rs +++ b/vit-servicing-station-lib/src/db/models/vote_options.rs @@ -2,8 +2,10 @@ use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::collections::HashMap; +pub type VoteOptionsMap = HashMap; + #[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)] -pub struct VoteOptions(pub HashMap); +pub struct VoteOptions(pub VoteOptionsMap); impl VoteOptions { pub fn parse_coma_separated_value(csv: &str) -> VoteOptions { diff --git a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/funds.rs b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/funds.rs index c7339ff7..f40b73e7 100644 --- a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/funds.rs +++ b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/funds.rs @@ -8,43 +8,52 @@ use async_graphql::Context; #[async_graphql::Object] impl Fund { + #[field(desc = "Fund ID")] pub async fn id(&self) -> i32 { self.id } + #[field(desc = "Fund Name")] pub async fn fund_name(&self) -> &str { &self.fund_name } + #[field(desc = "Fund Goal")] pub async fn fund_goal(&self) -> &str { &self.fund_goal } + #[field(desc = "Fund voting information")] pub async fn voting_power_info(&self) -> &str { &self.voting_power_info } + #[field(desc = "Fund rewards information")] pub async fn rewards_info(&self) -> &str { &self.rewards_info } + #[field(desc = "Fund start time, rfc3339 formatted")] pub async fn fund_start_time(&self) -> String { unix_timestamp_to_datetime(self.fund_start_time).to_rfc3339() } + #[field(desc = "Fund end time, rfc3339 formatted")] pub async fn fund_end_time(&self) -> String { unix_timestamp_to_datetime(self.fund_end_time).to_rfc3339() } + #[field(desc = "Next fund start time, rfc3339 formatted")] pub async fn next_fund_start_time(&self) -> String { unix_timestamp_to_datetime(self.next_fund_start_time).to_rfc3339() } + #[field(desc = "Fund chain voteplans")] pub async fn chain_vote_plans( &self, ctx: &Context<'_>, ) -> async_graphql::FieldResult> { - let pool = ctx.data::(); + let pool = ctx.data::().unwrap(); voteplans_queries::query_voteplan_by_id(self.id, pool) .await .map_err(async_graphql::FieldError::from) diff --git a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/mod.rs b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/mod.rs index 43d128f3..32dba1ee 100644 --- a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/mod.rs +++ b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/mod.rs @@ -1,6 +1,5 @@ pub mod funds; pub mod proposals; -pub mod vote_options; pub mod voteplans; use crate::db; diff --git a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/proposals.rs b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/proposals.rs index 56303388..4d2ce6e3 100644 --- a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/proposals.rs +++ b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/proposals.rs @@ -1,6 +1,8 @@ use crate::db::models::proposals::{Category, Proposal, Proposer}; use crate::db::models::vote_options::VoteOptions; use crate::utils::datetime::unix_timestamp_to_datetime; +use async_graphql::OutputJson; + #[async_graphql::Object] impl Category { pub async fn category_id(&self) -> &str { @@ -109,8 +111,8 @@ impl Proposal { unix_timestamp_to_datetime(self.chain_committee_end_time).to_rfc3339() } - pub async fn chain_vote_options(&self) -> VoteOptions { - self.chain_vote_options.clone() + pub async fn chain_vote_options(&self) -> OutputJson<&VoteOptions> { + OutputJson(&self.chain_vote_options) } pub async fn fund_id(&self) -> i32 { diff --git a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/vote_options.rs b/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/vote_options.rs deleted file mode 100644 index 45924bb9..00000000 --- a/vit-servicing-station-lib/src/v0/endpoints/graphql/schema/vote_options.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::db::models::vote_options::VoteOptions; -use async_graphql::registry::Registry; -use async_graphql::{ContextSelectionSet, Positioned}; -use std::borrow::Cow; - -#[async_trait::async_trait] -impl async_graphql::OutputValueType for VoteOptions { - async fn resolve( - &self, - _ctx: &ContextSelectionSet<'_>, - _field: &Positioned, - ) -> async_graphql::Result { - Ok(serde_json::to_value(&self.0).unwrap()) - } -} - -impl async_graphql::Type for VoteOptions { - fn type_name() -> Cow<'static, str> { - Cow::from("VoteOptions") - } - - fn create_type_info(_registry: &mut Registry) -> String { - Self::qualified_type_name() - } -}