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

proc-macro derive panicked #[derive(GraphQLQuery)]

Open gptguy opened this issue 6 years ago • 2 comments

 #[derive(GraphQLQuery)]
  |          ^^^^^^^^^^^^
  |
  = help: message: unnamed operation

Project fails to compile with the error above.

here are my imports:

use graphql_client::*;
use wasm_bindgen::prelude::*;
use web_sys::console;

#[derive(GraphQLQuery)]
#[graphql(
  query_path = "backend/users.graphql",
  schema_path = "backend/schema.json",
  response_derives = "Debug",
  deprecated = "warn"
)]
pub struct Users;

users.graphql:

query {
  users {
    id
    email
  }
}

gptguy avatar Nov 30 '19 07:11 gptguy

We should improve the error message, but the fix is to name the operation. For example:

query TheQuery {
  users {
    id
    email
  }
}

tomhoule avatar Dec 04 '19 07:12 tomhoule

I'm getting the same error even though my struct name is same as query, Transactions. The files queries.graphql and schema.json seem to be found. Line #[derive(GraphQLQuery)] is where the error occurs.

`use graphql_client::*;

#[derive(GraphQLQuery)] #[graphql( query_path = "src/common/gql/queries.graphql", schema_path = "src/common/gql/schema.json"
)] pub struct Transactions {}

query Transactions($ids: [ID!]) { transactions(ids: $ids) { edges { node { id signature } } } } `

jsoneaday avatar Sep 16 '22 20:09 jsoneaday