graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

macro error "wrong number of type arguments: expected 1, found 0"

Open malcolmrebughini opened this issue 4 years ago • 3 comments

Hi, I'm new to rust so sorry if this is just a newbie mistake.

I'm running into the following error:


error[E0107]: wrong number of type arguments: expected 1, found 0
 --> src\main.rs:9:10
  |
9 | #[derive(GraphQLQuery)]
  |          ^^^^^^^^^^^^ expected 1 type argument
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0107`.

main.rs:

#[derive(GraphQLQuery)]
#[graphql(
    schema_path = "./src/comments_schema.graphql",
    query_path = "./src/comments.graphql",
    response_derives = "Debug"
)]
struct Comments;

comments.graphql

query Comments($assetId: ID, $assetUrl: String) {
  asset(id: $assetId, url: $assetUrl) {
    title
    url
    created_at
    totalCommentCount
  }
}

I also tried to run with -Z macro-backtrace to see if I could get more info but doesn't seem to be a valid flag.

Thanks!

malcolmrebughini avatar May 12 '20 03:05 malcolmrebughini

Weird indeed, we'll have to look into this.

tomhoule avatar May 12 '20 06:05 tomhoule

@tomhoule Thanks for your response. Found a solution after a couple of hours of playing around. It was caused by some scalar types in my schema (and I must admit I'm not familiar with the schema).

The type in question was for Date, defined as:

scalar Date

So the compiler first errors out with:

error[E0412]: cannot find type `Date` in module `super`
  --> src\main.rs:18:10
   |
18 | #[derive(GraphQLQuery)]
   |          ^^^^^^^^^^^^ not found in `super`
   |
   = note: consider importing one of these items:
           chrono::Date
           chrono::prelude::Date
           crate::comments::Date
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Because I'm getting familiar with the language, I took that recommendation by importing chrono::Date and that is what ends up causing the error I've described.

I think this could just be solved by a clearer error message or maybe some documentation on how to handle this.

malcolmrebughini avatar May 12 '20 06:05 malcolmrebughini

I see - since it's a macro we really can't do better with the error message for missing scalars with the current architecture. There is a potential solution to improve the situation in this issue: https://github.com/graphql-rust/graphql-client/issues/245

tomhoule avatar May 12 '20 08:05 tomhoule