【发布时间】: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 文档?
-
你能创建一个沙箱吗?如果不进行一些试验,很难猜出发生了什么