graphql-rust / juniper

GraphQL server library for Rust
Other
5.69k stars 422 forks source link

`#[graphql_object]` hides syntax errors #1244

Closed 50U10FCA7 closed 8 months ago

50U10FCA7 commented 8 months ago

Describe the bug

#[graphql_object] attribute macro prevents syntax errors from being shown: https://github.com/graphql-rust/juniper/blob/8a69e14c8bbbbd1da8bdefe3e30c60ff342ed863/juniper_codegen/src/graphql_object/attr.rs#L35

To Reproduce Steps to reproduce the behavior:

  1. Add a valid struct;
  2. Impl fields resolvers with #[graphql_object];
  3. Broke syntax inside method impl.
struct MyObject {
  my_field: i32,
}

#[graphql_object] // ERROR: #[graphql_object] attribute is applicable to non-trait `impl` blocks only
impl MyObject {
    fn my_field(&self) -> i32 {
        self.self.my_field // actual syntax error is not reported.
    }
}

Expected behavior

A syntax error will be shown.

Additional context

The problem is happening because attribute macro ignores errors of impl block parsing: https://github.com/graphql-rust/juniper/blob/8a69e14c8bbbbd1da8bdefe3e30c60ff342ed863/juniper_codegen/src/graphql_object/attr.rs#L22

50U10FCA7 commented 8 months ago

@tyranron ping

tyranron commented 8 months ago

@50U10FCA7 could you show the expansion in this case?