'I am getting error when I am working on Strapi app using GrapQl

I am following this tutorial https://strapi.io/blog/nextjs-react-hooks-strapi-restaurants-2

My query is

{  
  restaurants { 
        id 
        name
    } 
}

Response

{
  "error": {
    "errors": [
      {
        "message": "Cannot query field \"id\" on type \"RestaurantEntityResponseCollection\".",
        "locations": [
          {
            "line": 3,
            "column": 5
          }
        ],
        "extensions": {
          "code": "GRAPHQL_VALIDATION_FAILED",
          "exception": {
            "stacktrace": [
              "GraphQLError: Cannot query field \"id\" on type \"RestaurantEntityResponseCollection\".",
      



Solution 1:[1]

You query is incorrect, it should be as follow docs:


 {
  restaurants{
    data{
      id
      attributes{
        name
        image{
          data{
            attributes{
              url
            }
          }
        }
      }
      
    }    
  }
}

Solution 2:[2]

New strapi versions doesnt work with that old tutorials

{
    restaurants {
        data {
            id
            attributes {
                name
                description
            }
        }
    }
}

It will resolve data like this:

{
  "data": {
    "restaurants": {
      "data": [
        {
          "id": "1",
          "attributes": {
            "name": "name 1",
            "description": "desc 1"
          }
        },
        {
          "id": "2",
          "attributes": {
            "name": "name 2",
            "description": "desc 2"
          }
        }
      ]
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shyakadev
Solution 2 otaneR ocraM