【问题标题】:error Cannot query field "allStrapiArticles" on type "Query"错误无法在“查询”类型上查询字段“allStrapiArticles”
【发布时间】: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”?

标签: graphql gatsby strapi


【解决方案1】:

我强烈建议降级到v2,直到所有插件和依赖项将其代码调整为当前稳定的v3。如您所知,Gatsby 最近刚刚发布了v3,它的代码非常适合“原生”用例采购,或者换句话说,在从降价、JSON 等收集数据时。

所有与插件相关的解决方法,或者从外部 CMS 获取数据时,总是需要插件,代码严格依赖于插件的实现,因此,直到 Strapi(在这种情况下)不更新代码,您将无法使用 Gatsby 的 v3 而不会遇到错误、问题或警告。

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 2021-10-09
    • 2021-12-09
    • 2018-10-30
    • 2021-07-26
    • 2021-02-03
    • 2020-07-27
    • 2018-08-30
    相关资源
    最近更新 更多