diff --git a/Cargo.toml b/Cargo.toml index 0db1ada4..c0f2520a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql" -version = "1.9.5" +version = "1.9.6" authors = ["sunli "] 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.5" } +async-graphql-derive = { path = "async-graphql-derive", version = "1.9.6" } graphql-parser = "=0.2.3" anyhow = "1.0.26" thiserror = "1.0.11" diff --git a/async-graphql-actix-web/Cargo.toml b/async-graphql-actix-web/Cargo.toml index d59b8433..f95ebea0 100644 --- a/async-graphql-actix-web/Cargo.toml +++ b/async-graphql-actix-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-actix-web" -version = "1.0.5" +version = "1.0.6" authors = ["sunli "] 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.5" } +async-graphql = { path = "..", version = "1.9.6" } actix-web = "2.0.0" actix-web-actors = "2.0.0" actix = "0.9.0" diff --git a/async-graphql-derive/Cargo.toml b/async-graphql-derive/Cargo.toml index 8836a56f..b1f4ab73 100644 --- a/async-graphql-derive/Cargo.toml +++ b/async-graphql-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-derive" -version = "1.9.5" +version = "1.9.6" authors = ["sunli "] edition = "2018" description = "Macros for async-graphql" diff --git a/async-graphql-derive/src/simple_object.rs b/async-graphql-derive/src/simple_object.rs index 24fab277..28c4933f 100644 --- a/async-graphql-derive/src/simple_object.rs +++ b/async-graphql-derive/src/simple_object.rs @@ -26,6 +26,7 @@ pub fn generate(object_args: &args::Object, input: &mut DeriveInput) -> Result Result quote! { Some(#provides) }, None => quote! { None }, }; + let vis = &item.vis; let ty = &item.ty; let cache_control = { @@ -88,6 +90,13 @@ pub fn generate(object_args: &args::Object, input: &mut DeriveInput) -> Result #ty { + self.#ident.clone() + } + }); + resolvers.push(quote! { if field.name.as_str() == #field_name { let ctx_obj = ctx.with_selection_set(&field.selection_set); @@ -121,7 +130,11 @@ pub fn generate(object_args: &args::Object, input: &mut DeriveInput) -> Result std::borrow::Cow<'static, str> { std::borrow::Cow::Borrowed(#gql_typename) } diff --git a/async-graphql-warp/Cargo.toml b/async-graphql-warp/Cargo.toml index 898c2c9a..7e552c8d 100644 --- a/async-graphql-warp/Cargo.toml +++ b/async-graphql-warp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "async-graphql-warp" -version = "1.0.6" +version = "1.0.7" authors = ["sunli "] 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.5" } +async-graphql = { path = "..", version = "1.9.6" } warp = "0.2.2" futures = "0.3.0" bytes = "0.5.4" diff --git a/tests/interface.rs b/tests/interface.rs index 40557a89..94d8a7a9 100644 --- a/tests/interface.rs +++ b/tests/interface.rs @@ -1,5 +1,52 @@ use async_graphql::*; +#[async_std::test] +pub async fn test_interface_simple_object() { + #[async_graphql::SimpleObject] + pub struct MyObj { + #[field] + pub id: i32, + #[field] + pub title: String, + } + + #[async_graphql::Interface(field(name = "id", type = "i32"))] + pub struct Node(MyObj); + + struct Query; + + #[Object] + impl Query { + #[field] + async fn node(&self) -> Node { + MyObj { + id: 33, + title: "haha".to_string(), + } + .into() + } + } + + let query = format!( + r#"{{ + node {{ + ... on Node {{ + id + }} + }} + }}"# + ); + let schema = Schema::new(Query, EmptyMutation, EmptySubscription); + assert_eq!( + schema.execute(&query).await.unwrap().data, + serde_json::json!({ + "node": { + "id": 33, + } + }) + ); +} + #[async_std::test] pub async fn test_multiple_interfaces() { struct MyObj;