2.0.0-alpha.27
This commit is contained in:
parent
34b6531576
commit
7aa26c3484
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "graphql-benchmark"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "Koxiaet"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "chat"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["Ivan Plesskih <terma95@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "simple"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["Ivan Plesskih <terma95@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-derive"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-actix-web"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-rocket"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["Daniel Wiesenberg <daniel@simplificAR.io>"]
|
||||
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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-tide"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["vkill <vkill.net@gmail.com>"]
|
||||
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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-warp"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-parser"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "async-graphql-value"
|
||||
version = "2.0.0-alpha.26"
|
||||
version = "2.0.0-alpha.27"
|
||||
authors = ["sunli <scott_s829@163.com>", "Koxiaet"]
|
||||
edition = "2018"
|
||||
description = "GraphQL value for async-graphql"
|
||||
|
|
|
@ -477,79 +477,3 @@ impl<'de> de::Deserializer<'de> for NameDeserializer {
|
|||
pub fn from_value<T: DeserializeOwned>(value: ConstValue) -> Result<T, DeserializerError> {
|
||||
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<i32> = from_value(ConstValue::Number(100i32.into())).unwrap();
|
||||
assert_eq!(n, Some(100));
|
||||
|
||||
let n: Option<i32> = from_value(ConstValue::Null).unwrap();
|
||||
assert_eq!(n, None);
|
||||
|
||||
let n: Vec<i32> = 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::<Name, ConstValue>::new();
|
||||
obj.insert(Name::new("A"), ConstValue::Number(10.into()));
|
||||
obj.insert(Name::new("B"), ConstValue::Number(20.into()));
|
||||
let n: HashMap<Enum, i32> = 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<Enum>,
|
||||
}
|
||||
let mut obj = BTreeMap::<Name, ConstValue>::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)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -484,9 +484,9 @@ impl serde::Serializer for MapKeySerializer {
|
|||
self,
|
||||
_name: &'static str,
|
||||
_variant_index: u32,
|
||||
_variant: &'static str,
|
||||
variant: &'static str,
|
||||
) -> Result<Self::Ok, Self::Error> {
|
||||
Err(key_must_be_a_string())
|
||||
Ok(Name::new(variant))
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct<T: ?Sized>(
|
||||
|
|
54
value/tests/test_serde.rs
Normal file
54
value/tests/test_serde.rs
Normal file
|
@ -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<T: Serialize + DeserializeOwned + Clone + PartialEq + Debug>(value: T) {
|
||||
assert_eq!(
|
||||
from_value::<T>(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::<Name, ConstValue>::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::<Enum, ConstValue>::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<Enum>,
|
||||
}
|
||||
test_value(Struct {
|
||||
a: 100,
|
||||
b: Some(Enum::B),
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user