This commit is contained in:
sunli 2020-04-22 13:30:41 +08:00
parent 3473c8e5ad
commit 00513ffb02
6 changed files with 61 additions and 16 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "async-graphql"
version = "1.9.8"
version = "1.9.9"
authors = ["sunli <scott_s829@163.com>"]
edition = "2018"
description = "The GraphQL server library implemented by rust"
@ -18,7 +18,7 @@ default = ["bson", "uuid", "url", "chrono-tz", "validators"]
validators = ["regex"]
[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"
anyhow = "1.0.26"
thiserror = "1.0.11"

View File

@ -1,6 +1,6 @@
[package]
name = "async-graphql-actix-web"
version = "1.0.8"
version = "1.0.9"
authors = ["sunli <scott_s829@163.com>"]
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 = "1.9.8" }
async-graphql = { path = "..", version = "1.9.9" }
actix-web = "2.0.0"
actix-web-actors = "2.0.0"
actix = "0.9.0"

View File

@ -1,6 +1,6 @@
[package]
name = "async-graphql-derive"
version = "1.9.8"
version = "1.9.9"
authors = ["sunli <scott_s829@163.com>"]
edition = "2018"
description = "Macros for async-graphql"

View File

@ -223,7 +223,7 @@ pub fn generate(interface_args: &args::Interface, input: &DeriveInput) -> Result
OutputType::Result(_, _) => {
quote! {
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()))?
}
}
};

View File

@ -1,6 +1,6 @@
[package]
name = "async-graphql-warp"
version = "1.0.9"
version = "1.0.10"
authors = ["sunli <scott_s829@163.com>"]
edition = "2018"
description = "async-graphql for warp"
@ -13,7 +13,7 @@ keywords = ["futures", "async", "graphql"]
categories = ["network-programming", "asynchronous"]
[dependencies]
async-graphql = { path = "..", version = "1.9.8" }
async-graphql = { path = "..", version = "1.9.9" }
warp = "0.2.2"
futures = "0.3.0"
bytes = "0.5.4"

View File

@ -3,15 +3,15 @@ use async_graphql::*;
#[async_std::test]
pub async fn test_interface_simple_object() {
#[async_graphql::SimpleObject]
pub struct MyObj {
struct MyObj {
#[field]
pub id: i32,
id: i32,
#[field]
pub title: String,
title: String,
}
#[async_graphql::Interface(field(name = "id", type = "i32"))]
pub struct Node(MyObj);
struct Node(MyObj);
struct Query;
@ -50,15 +50,15 @@ pub async fn test_interface_simple_object() {
#[async_std::test]
pub async fn test_interface_simple_object2() {
#[async_graphql::SimpleObject]
pub struct MyObj {
struct MyObj {
#[field(ref)]
pub id: i32,
id: i32,
#[field]
pub title: String,
title: String,
}
#[async_graphql::Interface(field(name = "id", type = "&i32"))]
pub struct Node(MyObj);
struct Node(MyObj);
struct Query;
@ -161,3 +161,48 @@ pub async fn test_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,
}
})
);
}