Merge branch 'master' into interface-test
This commit is contained in:
commit
7e481b5bde
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "async-graphql"
|
name = "async-graphql"
|
||||||
version = "1.9.8"
|
version = "1.9.9"
|
||||||
authors = ["sunli <scott_s829@163.com>"]
|
authors = ["sunli <scott_s829@163.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "The GraphQL server library implemented by rust"
|
description = "The GraphQL server library implemented by rust"
|
||||||
|
@ -18,7 +18,7 @@ default = ["bson", "uuid", "url", "chrono-tz", "validators"]
|
||||||
validators = ["regex"]
|
validators = ["regex"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-graphql-derive = { path = "async-graphql-derive", version = "1.9.8" }
|
async-graphql-derive = { path = "async-graphql-derive", version = "1.9.9" }
|
||||||
graphql-parser = "=0.2.3"
|
graphql-parser = "=0.2.3"
|
||||||
anyhow = "1.0.26"
|
anyhow = "1.0.26"
|
||||||
thiserror = "1.0.11"
|
thiserror = "1.0.11"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "async-graphql-actix-web"
|
name = "async-graphql-actix-web"
|
||||||
version = "1.0.8"
|
version = "1.0.9"
|
||||||
authors = ["sunli <scott_s829@163.com>"]
|
authors = ["sunli <scott_s829@163.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "async-graphql for actix-web"
|
description = "async-graphql for actix-web"
|
||||||
|
@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"]
|
||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-graphql = { path = "..", version = "1.9.8" }
|
async-graphql = { path = "..", version = "1.9.9" }
|
||||||
actix-web = "2.0.0"
|
actix-web = "2.0.0"
|
||||||
actix-web-actors = "2.0.0"
|
actix-web-actors = "2.0.0"
|
||||||
actix = "0.9.0"
|
actix = "0.9.0"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "async-graphql-derive"
|
name = "async-graphql-derive"
|
||||||
version = "1.9.8"
|
version = "1.9.9"
|
||||||
authors = ["sunli <scott_s829@163.com>"]
|
authors = ["sunli <scott_s829@163.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Macros for async-graphql"
|
description = "Macros for async-graphql"
|
||||||
|
|
|
@ -223,7 +223,7 @@ pub fn generate(interface_args: &args::Interface, input: &DeriveInput) -> Result
|
||||||
OutputType::Result(_, _) => {
|
OutputType::Result(_, _) => {
|
||||||
quote! {
|
quote! {
|
||||||
self.#method_name(#(#use_params),*).await.
|
self.#method_name(#(#use_params),*).await.
|
||||||
map_err(|err| err.with_position(field.position))?
|
map_err(|err| err.into_error_with_path(field.position, ctx.path_node.as_ref().unwrap().to_json()))?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "async-graphql-warp"
|
name = "async-graphql-warp"
|
||||||
version = "1.0.9"
|
version = "1.0.10"
|
||||||
authors = ["sunli <scott_s829@163.com>"]
|
authors = ["sunli <scott_s829@163.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "async-graphql for warp"
|
description = "async-graphql for warp"
|
||||||
|
@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"]
|
||||||
categories = ["network-programming", "asynchronous"]
|
categories = ["network-programming", "asynchronous"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-graphql = { path = "..", version = "1.9.8" }
|
async-graphql = { path = "..", version = "1.9.9" }
|
||||||
warp = "0.2.2"
|
warp = "0.2.2"
|
||||||
futures = "0.3.0"
|
futures = "0.3.0"
|
||||||
bytes = "0.5.4"
|
bytes = "0.5.4"
|
||||||
|
|
|
@ -3,15 +3,15 @@ use async_graphql::*;
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
pub async fn test_interface_simple_object() {
|
pub async fn test_interface_simple_object() {
|
||||||
#[async_graphql::SimpleObject]
|
#[async_graphql::SimpleObject]
|
||||||
pub struct MyObj {
|
struct MyObj {
|
||||||
#[field]
|
#[field]
|
||||||
pub id: i32,
|
id: i32,
|
||||||
#[field]
|
#[field]
|
||||||
pub title: String,
|
title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_graphql::Interface(field(name = "id", type = "i32"))]
|
#[async_graphql::Interface(field(name = "id", type = "i32"))]
|
||||||
pub struct Node(MyObj);
|
struct Node(MyObj);
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
|
@ -50,15 +50,15 @@ pub async fn test_interface_simple_object() {
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
pub async fn test_interface_simple_object2() {
|
pub async fn test_interface_simple_object2() {
|
||||||
#[async_graphql::SimpleObject]
|
#[async_graphql::SimpleObject]
|
||||||
pub struct MyObj {
|
struct MyObj {
|
||||||
#[field(ref)]
|
#[field(ref)]
|
||||||
pub id: i32,
|
id: i32,
|
||||||
#[field]
|
#[field]
|
||||||
pub title: String,
|
title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_graphql::Interface(field(name = "id", type = "&i32"))]
|
#[async_graphql::Interface(field(name = "id", type = "&i32"))]
|
||||||
pub struct Node(MyObj);
|
struct Node(MyObj);
|
||||||
|
|
||||||
struct Query;
|
struct Query;
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ pub async fn test_multiple_interfaces() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
pub async fn test_multiple_objects_in_multiple_interfaces() {
|
pub async fn test_multiple_objects_in_multiple_interfaces() {
|
||||||
struct MyObjOne;
|
struct MyObjOne;
|
||||||
|
|
||||||
#[async_graphql::Object]
|
#[async_graphql::Object]
|
||||||
|
@ -240,4 +240,50 @@ pub async fn test_multiple_objects_in_multiple_interfaces() {
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
pub async fn test_interface_field_result() {
|
||||||
|
struct MyObj;
|
||||||
|
|
||||||
|
#[async_graphql::Object]
|
||||||
|
impl MyObj {
|
||||||
|
#[field]
|
||||||
|
async fn value(&self) -> FieldResult<i32> {
|
||||||
|
Ok(10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_graphql::Interface(field(name = "value", type = "FieldResult<i32>"))]
|
||||||
|
struct Node(MyObj);
|
||||||
|
|
||||||
|
struct Query;
|
||||||
|
|
||||||
|
#[Object]
|
||||||
|
impl Query {
|
||||||
|
#[field]
|
||||||
|
async fn node(&self) -> Node {
|
||||||
|
MyObj.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let query = format!(
|
||||||
|
r#"{{
|
||||||
|
node {{
|
||||||
|
... on Node {{
|
||||||
|
value
|
||||||
|
}}
|
||||||
|
}}
|
||||||
|
}}"#
|
||||||
|
);
|
||||||
|
let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
||||||
|
assert_eq!(
|
||||||
|
schema.execute(&query).await.unwrap().data,
|
||||||
|
serde_json::json!({
|
||||||
|
"node": {
|
||||||
|
"value": 10,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user