【发布时间】:2021-06-03 10:09:23
【问题描述】:
我刚刚开始了我与 Strapi 和 Gatsby 的第一个项目。刚刚升级到 Gatsby CLI 3.0 后,我收到以下错误:
Cannot query field "allStrapiArticles" on type "Query"
我的整个文件:
import React from "React"
import { Link, graphql } from "gatsby"
import Navbar from "../components/navbar"
import Footer from "../components/footer"
const IndexPage = ({ data }) => (
<div>
<Navbar />
<h1>Articles</h1>
<p>Colleciton of Photo Editorials</p>
<ul>
{data.allStrapiArticles.edges.map(document => (
<li key={document.node.id}>
<h2>
<Link to={`/${document.node.id}`}>{document.node.Title}</Link>
</h2>
<p>{document.node.Snippet}</p>
</li>
))}
</ul>
<Footer />
</div>
)
export default IndexPage
export const pageQuery = graphql`
query IndexQuery {
allStrapiArticles {
edges {
node {
id
Title
Snippet
}
}
}
}
`
我的 Strapi 架构如下:
type Articles {
id: ID!
created_at: DateTime!
updated_at: DateTime!
Title: String
Snippet: String
Content: String
category: Category
published_at: DateTime
image(sort: String, limit: Int, start: Int, where: JSON): [UploadFile]
tags(sort: String, limit: Int, start: Int, where: JSON): [Tags]
}
由于使用单数“文章”,我最初确实遇到了问题,但已将其更正为复数,我还注意到这都是区分大小写的,并且需要大写的“标题”和“片段”。但正如我所说,在升级到 3.0 之前我已经正常工作了,我看不出 CLI 会如何影响它。
我错过了那个版本中的重大变化吗?
【问题讨论】:
-
你能不能用'allStrapiArticle'替换'allStrapiArticles',看看它是否有效。还只是为了确定发送请求的用户(经过身份验证的/公共)是否有权访问文章内容类型的“find”和“findOne”?