我在使用 GraphQl 开发 Strapi 应用程序时遇到错误
I am getting error when I am working on Strapi app using GrapQl
我正在学习本教程https://strapi.io/blog/nextjs-react-hooks-strapi-restaurants-2
我的查询是
{
restaurants {
id
name
}
}
回应
{
"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\".",
您的查询有误,应该如下docs:
{
restaurants{
data{
id
attributes{
name
image{
data{
attributes{
url
}
}
}
}
}
}
}
新版 strapi 不适用于旧教程
{
restaurants {
data {
id
attributes {
name
description
}
}
}
}
它将像这样解析数据:
{
"data": {
"restaurants": {
"data": [
{
"id": "1",
"attributes": {
"name": "name 1",
"description": "desc 1"
}
},
{
"id": "2",
"attributes": {
"name": "name 2",
"description": "desc 2"
}
}
]
}
}
}
我正在学习本教程https://strapi.io/blog/nextjs-react-hooks-strapi-restaurants-2
我的查询是
{
restaurants {
id
name
}
}
回应
{
"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\".",
您的查询有误,应该如下docs:
{
restaurants{
data{
id
attributes{
name
image{
data{
attributes{
url
}
}
}
}
}
}
}
新版 strapi 不适用于旧教程
{
restaurants {
data {
id
attributes {
name
description
}
}
}
}
它将像这样解析数据:
{
"data": {
"restaurants": {
"data": [
{
"id": "1",
"attributes": {
"name": "name 1",
"description": "desc 1"
}
},
{
"id": "2",
"attributes": {
"name": "name 2",
"description": "desc 2"
}
}
]
}
}
}