【发布时间】:2021-09-06 09:36:20
【问题描述】:
我使用 Gatsby 来创建页面,然后在 createPage 方法中我引用页面的特定组件
createPage({
path: node.path.alias,
component: path.resolve(`./src/layouts/custom-page/custom-page.js`),
context: {
articleId: node.id,
authorId: node.relationships.field_author.id
},
})
在布局内 (custom-page.js) 我正在尝试执行 2 个查询,但它对我不起作用。当我在 GraphiQL 中测试这个查询时,它工作正常。
export const query = graphql `
query ($articleId: String!, $authorId: String!) {
article: nodeArticle(id: {eq: $articleId}) {
title
body {
value
}
path {
alias
}
}
author: nodePerson(id: {eq: $authorId}) {
title
path {
alias
}
}
}
`;
在我的组件中,我希望能够使用data.author.title 或data.article.title 访问数据。
在 Gatsby 中可以做到这一点吗?
【问题讨论】: