Error: Network error: field "todos" not found in type: 'query_root'
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
What does your public schema look like? Is there a table called todos?
@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 Did you also check with permissions?
@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?
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 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 Did you also check with permissions?
Thank you so much, i was also struggling with this and your comment resolved all problems..
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.
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!?!
I have just spent 2 days trying to figure out the issue. This should be changed and provide more meaningful error messages
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.
In my case, the user's email was not verified. I just changed the email_verified_field in the user table to true.
In the Hasura database make sure you have Track the table to the database in Hasura
@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