Skip to content

Incorrect handling of types matched as idents #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions juniper/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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



Expand Down
6 changes: 6 additions & 0 deletions juniper_codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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



Expand Down
1 change: 1 addition & 0 deletions juniper_codegen/src/common/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
39 changes: 39 additions & 0 deletions tests/integration/src/inside_macro.rs
Original file line number Diff line number Diff line change
@@ -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}));
}
2 changes: 2 additions & 0 deletions tests/integration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down