Skip to content

Commit c40d80f

Browse files
authored
Fix expansion of procedural macros inside macro_rules! (#1054, #1051)
1 parent 1a6655e commit c40d80f

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

juniper/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
6565
- Unsupported spreading GraphQL interface fragments on unions and other interfaces. ([#965], [#798])
6666
- Unsupported expressions in `graphql_value!` macro. ([#996], [#503])
6767
- Incorrect GraphQL list coercion rules: `null` cannot be coerced to an `[Int!]!` or `[Int]!`. ([#1004])
68+
- All procedural macros expansion inside `macro_rules!`. ([#1054], [#1051])
6869

6970
[#503]: /../../issues/503
7071
[#750]: /../../issues/750
@@ -89,6 +90,8 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
8990
[#1017]: /../../pull/1017
9091
[#1025]: /../../pull/1025
9192
[#1026]: /../../pull/1026
93+
[#1051]: /../../issues/1051
94+
[#1054]: /../../pull/1054
9295

9396

9497

juniper_codegen/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ All user visible changes to `juniper_codegen` crate will be documented in this f
3737

3838
- `#[derive(GraphQLInterface)]` macro allowing using structs as GraphQL interfaces. ([#1026])
3939

40+
### Fixed
41+
42+
- All procedural macros expansion inside `macro_rules!`. ([#1054], [#1051])
43+
4044
[#971]: /../../pull/971
4145
[#985]: /../../pull/985
4246
[#987]: /../../pull/987
@@ -47,6 +51,8 @@ All user visible changes to `juniper_codegen` crate will be documented in this f
4751
[#1017]: /../../pull/1017
4852
[#1025]: /../../pull/1025
4953
[#1026]: /../../pull/1026
54+
[#1051]: /../../issues/1051
55+
[#1054]: /../../pull/1054
5056

5157

5258

juniper_codegen/src/common/parse/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ impl TypeExt for syn::Type {
127127
fn unparenthesized(&self) -> &Self {
128128
match self {
129129
Self::Paren(ty) => ty.elem.unparenthesized(),
130+
Self::Group(ty) => ty.elem.unparenthesized(),
130131
ty => ty,
131132
}
132133
}

tests/integration/src/inside_macro.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Checks that `#[graphql_object]` macro correctly expands inside a declarative
2+
//! macro definition.
3+
//! See [#1051](https://github.com/graphql-rust/juniper/pull/1051) and
4+
//! [#1054](https://github.com/graphql-rust/juniper/pull/1054) for details.
5+
6+
use juniper::{
7+
graphql_object, graphql_value, graphql_vars, EmptyMutation, EmptySubscription, RootNode,
8+
};
9+
10+
macro_rules! impl_id {
11+
($typename:ident) => {
12+
#[graphql_object]
13+
impl $typename {
14+
fn id(&self) -> i32 {
15+
42
16+
}
17+
}
18+
};
19+
}
20+
21+
struct Unit;
22+
impl_id!(Unit);
23+
24+
#[tokio::test]
25+
async fn works() {
26+
let query = r#"
27+
query Unit {
28+
id
29+
}
30+
"#;
31+
32+
let schema = RootNode::new(Unit, EmptyMutation::new(), EmptySubscription::new());
33+
let (res, errs) = juniper::execute(query, None, &schema, &graphql_vars! {}, &())
34+
.await
35+
.unwrap();
36+
37+
assert_eq!(errs.len(), 0);
38+
assert_eq!(res, graphql_value!({"id": 42}));
39+
}

tests/integration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ mod explicit_null;
1111
#[cfg(test)]
1212
mod infallible_as_field_error;
1313
#[cfg(test)]
14+
mod inside_macro;
15+
#[cfg(test)]
1416
mod issue_371;
1517
#[cfg(test)]
1618
mod issue_372;

0 commit comments

Comments
 (0)