diff --git a/Cargo.toml b/Cargo.toml index 12dfbca9..588448f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" description = "A GraphQL server library implemented in Rust" @@ -24,9 +24,9 @@ string_number = ["num-traits"] nightly = [] [dependencies] -async-graphql-derive = { path = "derive", version = "2.0.0-alpha.26" } -async-graphql-value = { path = "value", version = "2.0.0-alpha.26" } -async-graphql-parser = { path = "parser", version = "2.0.0-alpha.26" } +async-graphql-derive = { path = "derive", version = "2.0.0-alpha.27" } +async-graphql-value = { path = "value", version = "2.0.0-alpha.27" } +async-graphql-parser = { path = "parser", version = "2.0.0-alpha.27" } async-stream = "0.3" async-trait = "0.1.30" diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml index 37a287fa..fbee9079 100644 --- a/benchmark/Cargo.toml +++ b/benchmark/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "graphql-benchmark" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" diff --git a/benchmark/chat/Cargo.toml b/benchmark/chat/Cargo.toml index 192cd984..891c40f6 100644 --- a/benchmark/chat/Cargo.toml +++ b/benchmark/chat/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chat" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["Ivan Plesskih "] edition = "2018" diff --git a/benchmark/simple/Cargo.toml b/benchmark/simple/Cargo.toml index 625b23be..568521e4 100644 --- a/benchmark/simple/Cargo.toml +++ b/benchmark/simple/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["Ivan Plesskih "] edition = "2018" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 55d11cc2..0e0936e6 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-derive" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" description = "Macros for async-graphql" @@ -16,7 +16,7 @@ categories = ["network-programming", "asynchronous"] proc-macro = true [dependencies] -async-graphql-parser = { path = "../parser", version = "2.0.0-alpha.26" } +async-graphql-parser = { path = "../parser", version = "2.0.0-alpha.27" } proc-macro2 = "1.0.6" syn = { version = "1.0.20", features = ["full", "extra-traits"] } quote = "1.0.3" diff --git a/integrations/actix-web/Cargo.toml b/integrations/actix-web/Cargo.toml index eff694f8..302ebd65 100644 --- a/integrations/actix-web/Cargo.toml +++ b/integrations/actix-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-actix-web" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" description = "async-graphql for actix-web" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.26" } +async-graphql = { path = "../..", version = "2.0.0-alpha.27" } actix-web = { version = "3.0.2", default-features = false } actix-web-actors = "3.0.0" actix-http = "2.0.0" diff --git a/integrations/rocket/Cargo.toml b/integrations/rocket/Cargo.toml index 5fef0b4a..92c335f5 100644 --- a/integrations/rocket/Cargo.toml +++ b/integrations/rocket/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-rocket" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["Daniel Wiesenberg "] edition = "2018" description = "async-graphql for Rocket.rs" @@ -14,7 +14,7 @@ keywords = ["futures", "async", "graphql", "rocket"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.26" } +async-graphql = { path = "../..", version = "2.0.0-alpha.27" } rocket = { git = "https://github.com/SergioBenitez/Rocket/", rev = "dc2c6ec", default-features = false } #TODO: Change to Cargo crate, when Rocket 0.5.0 is released log = "0.4.11" yansi = "0.5.0" diff --git a/integrations/tide/Cargo.toml b/integrations/tide/Cargo.toml index 54f990cd..138f70c0 100644 --- a/integrations/tide/Cargo.toml +++ b/integrations/tide/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-tide" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["vkill "] edition = "2018" description = "async-graphql for tide" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.26" } +async-graphql = { path = "../..", version = "2.0.0-alpha.27" } tide = { version = "0.13.0", default-features = false, features = ["h1-server"] } async-trait = "0.1.36" serde_json = "1.0.56" diff --git a/integrations/warp/Cargo.toml b/integrations/warp/Cargo.toml index 505e57ad..b4d68a5b 100644 --- a/integrations/warp/Cargo.toml +++ b/integrations/warp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-warp" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" description = "async-graphql for warp" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql = { path = "../..", version = "2.0.0-alpha.26" } +async-graphql = { path = "../..", version = "2.0.0-alpha.27" } warp = { version = "0.2", default-features = false, features = ["websocket"] } futures = "0.3.0" bytes = "0.5.4" diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 3734586a..8b7c2835 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-parser" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" description = "GraphQL query parser for async-graphql" @@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"] categories = ["network-programming", "asynchronous"] [dependencies] -async-graphql-value = { path = "../value", version = "2.0.0-alpha.26" } +async-graphql-value = { path = "../value", version = "2.0.0-alpha.27" } pest = "2.1.3" pest_derive = "2.1.0" serde_json = "1.0.57" diff --git a/value/Cargo.toml b/value/Cargo.toml index 353d2086..cc108777 100644 --- a/value/Cargo.toml +++ b/value/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-value" -version = "2.0.0-alpha.26" +version = "2.0.0-alpha.27" authors = ["sunli ", "Koxiaet"] edition = "2018" description = "GraphQL value for async-graphql" diff --git a/value/src/de.rs b/value/src/de.rs index 34bf18a1..05a7b54d 100644 --- a/value/src/de.rs +++ b/value/src/de.rs @@ -477,79 +477,3 @@ impl<'de> de::Deserializer<'de> for NameDeserializer { pub fn from_value(value: ConstValue) -> Result { T::deserialize(value) } - -#[cfg(test)] -mod tests { - use super::*; - use crate::Number; - use serde::Deserialize; - use std::collections::HashMap; - - #[test] - fn test_deserializer() { - let n: bool = from_value(ConstValue::Boolean(true)).unwrap(); - assert_eq!(n, true); - - let n: i32 = from_value(ConstValue::Number(100i32.into())).unwrap(); - assert_eq!(n, 100); - - let n: f32 = from_value(ConstValue::Number(Number::from_f64(1.123f64).unwrap())).unwrap(); - assert_eq!(n, 1.123); - - let n: Option = from_value(ConstValue::Number(100i32.into())).unwrap(); - assert_eq!(n, Some(100)); - - let n: Option = from_value(ConstValue::Null).unwrap(); - assert_eq!(n, None); - - let n: Vec = from_value( - (0..10) - .into_iter() - .map(|v| ConstValue::Number(v.into())) - .collect(), - ) - .unwrap(); - assert_eq!(n, vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); - - #[derive(Deserialize)] - struct NewType(i32); - - let n: NewType = from_value(ConstValue::Number(100i32.into())).unwrap(); - assert_eq!(n.0, 100); - - #[derive(Deserialize, Debug, Eq, PartialEq, Hash, Copy, Clone)] - enum Enum { - A, - B, - } - let n: Enum = from_value(ConstValue::String("A".to_string())).unwrap(); - assert_eq!(n, Enum::A); - - let n: Enum = from_value(ConstValue::Enum(Name::new("B"))).unwrap(); - assert_eq!(n, Enum::B); - - let mut obj = BTreeMap::::new(); - obj.insert(Name::new("A"), ConstValue::Number(10.into())); - obj.insert(Name::new("B"), ConstValue::Number(20.into())); - let n: HashMap = from_value(ConstValue::Object(obj)).unwrap(); - assert_eq!(10, n[&Enum::A]); - assert_eq!(20, n[&Enum::B]); - - #[derive(Deserialize, Debug, Eq, PartialEq)] - struct Struct { - a: i32, - b: Option, - } - let mut obj = BTreeMap::::new(); - obj.insert(Name::new("a"), ConstValue::Number(10.into())); - obj.insert(Name::new("b"), ConstValue::Enum(Name::new("B"))); - let n: Struct = from_value(ConstValue::Object(obj)).unwrap(); - assert_eq!( - n, - Struct { - a: 10, - b: Some(Enum::B) - } - ); - } -} diff --git a/value/src/ser.rs b/value/src/ser.rs index cd611421..ed5edd07 100644 --- a/value/src/ser.rs +++ b/value/src/ser.rs @@ -484,9 +484,9 @@ impl serde::Serializer for MapKeySerializer { self, _name: &'static str, _variant_index: u32, - _variant: &'static str, + variant: &'static str, ) -> Result { - Err(key_must_be_a_string()) + Ok(Name::new(variant)) } fn serialize_newtype_struct( diff --git a/value/tests/test_serde.rs b/value/tests/test_serde.rs new file mode 100644 index 00000000..b27d7ac7 --- /dev/null +++ b/value/tests/test_serde.rs @@ -0,0 +1,54 @@ +use async_graphql_value::*; +use serde::de::DeserializeOwned; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; +use std::fmt::Debug; + +fn test_value(value: T) { + assert_eq!( + from_value::(to_value(value.clone()).unwrap()).unwrap(), + value + ) +} + +#[test] +fn test_serde() { + test_value(true); + test_value(100i32); + test_value(1.123f64); + test_value(Some(100i32)); + test_value(ConstValue::Null); + test_value(vec![0i32, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + + #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone)] + struct NewType(i32); + test_value(NewType(100i32)); + + #[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Copy, Clone, Ord, PartialOrd)] + enum Enum { + A, + B, + } + test_value(Enum::A); + test_value(Enum::B); + + let mut obj = BTreeMap::::new(); + obj.insert(Name::new("A"), ConstValue::Number(10.into())); + obj.insert(Name::new("B"), ConstValue::Number(20.into())); + test_value(obj); + + let mut obj = BTreeMap::::new(); + obj.insert(Enum::A, ConstValue::Number(10.into())); + obj.insert(Enum::B, ConstValue::Number(20.into())); + test_value(obj); + + #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] + struct Struct { + a: i32, + b: Option, + } + test_value(Struct { + a: 100, + b: Some(Enum::B), + }); +}