graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

GraphQLInputObject macro fails if crate has a local type alias named "Result" #1194

Closed LGUG2Z closed 1 year ago

LGUG2Z commented 1 year ago

Describe the bug In a crate with this type alias:

type Result<T> = std::result::Result<T, diesel::result::Error>;

Deriving GraphQLInputObject for structs that include optional values will fail.

To Reproduce

Given the above type alias, and the following struct

#[derive(juniper::GraphQLInputObject)]
#[graphql(name = "UserInformation")]
pub struct Update {
    pub email: Option<String>,
    pub username: Option<String>,
}

The following error is returned:

error[E0107]: type alias takes 1 generic argument but 2 generic arguments were supplied
  --> models/src/user.rs:29:51
   |
29 | #[derive(Serialize, Deserialize, Debug, Validate, juniper::GraphQLInputObject)]
   |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                                                   |
   |                                                   expected 1 generic argument
   |                                                   help: remove this generic argument
   |
note: type alias defined here, with 1 generic parameter: `T`
  --> models/src/lib.rs:52:6
   |
52 | type Result<T> = std::result::Result<T, diesel::result::Error>;
   |      ^^^^^^ -
   = note: this error originates in the derive macro `juniper::GraphQLInputObject` (in Nightly builds, run with -Z macro-backtrace for more info)

Expected behavior

Successful compilation, as happens when the type alias is renamed to anything else, for example, there are no issues with the following:

type DatabaseResult<T> = std::result::Result<T, diesel::result::Error>;

Additional context

juniper = { git = "https://github.com/graphql-rust/juniper.git", rev ="984973658217f73d63608283d18723e11ce65161", default-features = false, features = ["schema-language", "url", "chrono"] }