diff --git a/juniper/CHANGELOG.md b/juniper/CHANGELOG.md index 600361192..149b7e151 100644 --- a/juniper/CHANGELOG.md +++ b/juniper/CHANGELOG.md @@ -65,6 +65,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi - Unsupported spreading GraphQL interface fragments on unions and other interfaces. ([#965], [#798]) - Unsupported expressions in `graphql_value!` macro. ([#996], [#503]) - Incorrect GraphQL list coercion rules: `null` cannot be coerced to an `[Int!]!` or `[Int]!`. ([#1004]) +- All procedural macros expansion inside `macro_rules!`. ([#1054], [#1051]) [#503]: /../../issues/503 [#750]: /../../issues/750 @@ -89,6 +90,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi [#1017]: /../../pull/1017 [#1025]: /../../pull/1025 [#1026]: /../../pull/1026 +[#1051]: /../../issues/1051 +[#1054]: /../../pull/1054 diff --git a/juniper_codegen/CHANGELOG.md b/juniper_codegen/CHANGELOG.md index 9afc81437..2ce86c70c 100644 --- a/juniper_codegen/CHANGELOG.md +++ b/juniper_codegen/CHANGELOG.md @@ -37,6 +37,10 @@ All user visible changes to `juniper_codegen` crate will be documented in this f - `#[derive(GraphQLInterface)]` macro allowing using structs as GraphQL interfaces. ([#1026]) +### Fixed + +- All procedural macros expansion inside `macro_rules!`. ([#1054], [#1051]) + [#971]: /../../pull/971 [#985]: /../../pull/985 [#987]: /../../pull/987 @@ -47,6 +51,8 @@ All user visible changes to `juniper_codegen` crate will be documented in this f [#1017]: /../../pull/1017 [#1025]: /../../pull/1025 [#1026]: /../../pull/1026 +[#1051]: /../../issues/1051 +[#1054]: /../../pull/1054 diff --git a/juniper_codegen/src/common/parse/mod.rs b/juniper_codegen/src/common/parse/mod.rs index c9c79dc72..eaa946d99 100644 --- a/juniper_codegen/src/common/parse/mod.rs +++ b/juniper_codegen/src/common/parse/mod.rs @@ -127,6 +127,7 @@ impl TypeExt for syn::Type { fn unparenthesized(&self) -> &Self { match self { Self::Paren(ty) => ty.elem.unparenthesized(), + Self::Group(ty) => ty.elem.unparenthesized(), ty => ty, } } diff --git a/tests/integration/src/inside_macro.rs b/tests/integration/src/inside_macro.rs new file mode 100644 index 000000000..f94b6f999 --- /dev/null +++ b/tests/integration/src/inside_macro.rs @@ -0,0 +1,39 @@ +//! Checks that `#[graphql_object]` macro correctly expands inside a declarative +//! macro definition. +//! See [#1051](https://github.com/graphql-rust/juniper/pull/1051) and +//! [#1054](https://github.com/graphql-rust/juniper/pull/1054) for details. + +use juniper::{ + graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, RootNode, +}; + +macro_rules! impl_id { + ($typename:ident) => { + #[graphql_object] + impl $typename { + fn id(&self) -> i32 { + 42 + } + } + }; +} + +struct Unit; +impl_id!(Unit); + +#[tokio::test] +async fn works() { + let query = r#" + query Unit { + id + } + "#; + + let schema = RootNode::new(Unit, EmptyMutation::new(), EmptySubscription::new()); + let (res, errs) = juniper::execute(query, None, &schema, &graphql_vars! {}, &()) + .await + .unwrap(); + + assert_eq!(errs.len(), 0); + assert_eq!(res, graphql_value!({"id": 42})); +} diff --git a/tests/integration/src/lib.rs b/tests/integration/src/lib.rs index 2e59d8c30..9b283001d 100644 --- a/tests/integration/src/lib.rs +++ b/tests/integration/src/lib.rs @@ -11,6 +11,8 @@ mod explicit_null; #[cfg(test)] mod infallible_as_field_error; #[cfg(test)] +mod inside_macro; +#[cfg(test)] mod issue_371; #[cfg(test)] mod issue_372;