【发布时间】:2022-01-14 02:33:07
【问题描述】:
自从 Strapi 更改为从未使用过的 V4 结构后,它破坏了我用来根据从 Strapi 返回的数据创建页面的 V3 查询。
我的 Gatsby-node.js 文件中使用 createPages 功能的代码如下:
const path = require(`path`)
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const result = await graphql(`
{
allStrapiArticles {
edges {
node {
data {
id
attributes {
title
}
}
}
}
}
}
`)
result.data.allStrapiArticles.edges[0].node.data.forEach(article => {
createPage({
path: `/blog/${article.attributes.title.replace(" ", "_")}`,
component: path.resolve(`src/templates/blog/index.js`),
context: {
id: article.id,
},
})
})
}
然后在页面模板中,我使用以下查询引用作为上下文传入的 id:
export const query = graphql`
query ($id: String!) {
strapiArticles(id: { eq: $id }) {
data {
id
attributes {
title
author
body
}
}
}
}
这似乎返回了一个 undefined 值。
是否有人熟悉必须如何更改此查询以符合 Strapi 的新结构?
基本上,我试图根据从 Gatsby-node.js 作为上下文传入的对象 ID 访问标题、作者和正文属性
【问题讨论】:
标签: reactjs graphql gatsby strapi