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

Error: Network error: field "todos" not found in type: 'query_root'

Open wave-light opened this issue 5 years ago • 14 comments

Hi I was following the NextJS Fullstack tutorial https://hasura.io/learn/graphql/nextjs-fullstack-serverless/queries/2-create-query/. After logging in with Auth0 in the frontend NextJS app, I am getting an error in the console when I try to fetch todos:

Error: Network error: field "todos" not found in type: 'query_root'

The query is:

const GET_MY_TODOS = gql`
  query getMyTodos {
    todos(where: { is_public: { _eq: false} }, order_by: { created_at: desc }) {
      id
      title
      created_at
      is_completed
  }
 }`;

When I run the same query in GraphiQL, using the x-hasura-admin-secret header it works as expected. Could you kindly advise what I doing wrong? Thanks

wave-light avatar Mar 25 '21 19:03 wave-light

What does your public schema look like? Is there a table called todos?

MarcelloTheArcane avatar Mar 26 '21 10:03 MarcelloTheArcane

@MarcelloTheArcane Yes, I ran the migrations and applied the metadata. When I run the query from GraphiQL, I get an empty array for the todos, which is expected. However, when I run the query from the frontend NextJS app, I get the error mentioned above.

wave-light avatar Mar 26 '21 12:03 wave-light

@wave-light Did you also check with permissions?

ashishdocforce avatar Mar 26 '21 13:03 ashishdocforce

@ashishdocforce Thanks so much! This was the issue - I hadn't granted the column permissions to the user role. Do you know why this permsions assignment wasn't included in the metadata?

wave-light avatar Mar 26 '21 13:03 wave-light

Hi, Thanks for useful information. Please tell me this solution in detail. In my case, I am facing with same problem but, I can't find user role column in my hasura cloud. when did you set user role in this tutorial?

nisaji avatar Apr 08 '21 09:04 nisaji

@nisaji the tutorial is missing quite a few steps. You are better to follow the backend tutorial to learn how to create a user role, and control the permissions. Here is the section that is relevant for your query: https://hasura.io/learn/graphql/hasura/authorization/1-todos-table-permissions/

wave-light avatar Apr 08 '21 17:04 wave-light

@wave-light Did you also check with permissions?

Thank you so much, i was also struggling with this and your comment resolved all problems..

jagdishlove avatar Dec 08 '21 03:12 jagdishlove

For those encountering this issue, I have updated the metadata to include the necessary permissions for ease of use. Here's the source for the hasura project.

Initially, it was meant to be a boilerplate where the backend tutorial would be followed by the user, but I have realised more and more people were stuck with some steps and hence the change.

praveenweb avatar Jul 24 '22 15:07 praveenweb

Am I the only one wondering why permission error results in the irrelevant error message? 🤔 Shouldn't the text be like You don't have a permission to invoke this action!?!

ivan-kleshnin avatar Aug 09 '22 06:08 ivan-kleshnin

I have just spent 2 days trying to figure out the issue. This should be changed and provide more meaningful error messages

msgadi avatar Dec 07 '22 06:12 msgadi

This error message is very general because specifically telling the caller "you don't have permission to invoke this action" would be leaking information: it would disclose to the caller that such an action exists.

When writing error messages, we do our best not to disclose any information to a potential attacker, and so when it comes to auth failures, we do not distinguish between a permissions failure and a non-existent resource.

That said, the error message could provide a hint about what could have gone wrong, as long as it does the same in both cases. We plan on improving error messages in the future; we'll definitely take this feedback to heart when doing so.

SamirTalwar avatar Dec 16 '22 07:12 SamirTalwar

In my case, the user's email was not verified. I just changed the email_verified_field in the user table to true.

argenisleon avatar Feb 01 '23 14:02 argenisleon

In the Hasura database make sure you have Track the table to the database in Hasura

trinhminhhieu avatar Jul 01 '23 04:07 trinhminhhieu

@trinhminhhieu How do you track all the tables and views in hasura-v2.xx ?

Cause I tried with this:

hasura metadata track --all-tables --all-relationships --schema public --endpoint http://graphql-engine:8080

And these no longer work anymore on v2.xx

maifeeulasad avatar Sep 26 '23 10:09 maifeeulasad