【问题标题】:Unknown Type of Strapi/Gatsby Graphql Query Fragment未知类型的 Strapi/Gatsby Graphql 查询片段
【发布时间】:2021-06-20 14:51:09
【问题描述】:

我正在尝试在 Gatsby 的 Strapi 动态区域内查询数据。在 Graphql Playground 中,我可以让它工作,但在 Gatsby 中使用相同的查询,我在终端中收到以下错误:

error Unknown type "ComponentTextArticleCopy" graphql/template-strings

还有我在article.js中的查询

export const query = graphql`
  query ArticleTemplate($id: String!) {
    strapiArticle(id: { eq: $id }) {
        articleHeader {
            articleTitle
            articleSnippet
          }
          articleContent {
            __typename
            ... on ComponentTextArticleCopy {
              contentCopy
            }
            ... on ComponentImageContentImg {
              imgCaption
            }
            ... on ComponentTextArticleQuote {
              contentQuote
            }
          }
    }
  }
`

根据Graphql docs 的说法,Inline Fragment 似乎是正确的方法,但显然我在某个地方出了点问题。

以下查询在 Gatsby 上“有效”,但尝试解析所有组件:

query MyQuery {
  allStrapiArticle {
    edges {
      node {
        __typename
        articleContent {
          contentCopy
          contentQuote
        }
      }
    }
  }
}
{
  "data": {
    "allStrapiArticle": {
      "edges": [
        {
          "node": {
            "__typename": "StrapiArticle",
            "articleContent": [
              {
                "contentCopy": null,
                "contentQuote": null
              },
              {
                "contentCopy": "What a great city Gothenburg is.  We even took a trip out to the archipelago. ",
                "contentQuote": null
              },
              {
                "contentCopy": null,
                "contentQuote": null
              },
              {
                "contentCopy": null,
                "contentQuote": "You must visit at have fika"
              }
            ]
          }
        }
      ]
    }
  },

【问题讨论】:

  • 盖茨比呢?游乐场,文档?
  • ... gatsby fragments 文档?
  • 你能创建一个沙箱吗?如果不进行一些试验,很难猜出发生了什么

标签: graphql gatsby strapi


【解决方案1】:

删除缓存文件夹并再次运行对我有用。

【讨论】:

  • 只是为了帮助刚接触 Strapi 的人填补空白,你能指定 Cache 文件夹的位置吗?
猜你喜欢
  • 2020-10-29
  • 2020-06-28
  • 2021-11-13
  • 1970-01-01
  • 2021-05-14
  • 2021-09-05
  • 2020-01-19
  • 2021-04-13
  • 2020-10-25
相关资源
最近更新 更多