【发布时间】:2020-08-17 17:51:12
【问题描述】:
我需要在一个组件和gatsby-node.js 文件中运行多个graphQL 查询。 (因为 Prismic 每个答案限制为 20 个条目...????)
我尝试了以下方法,只是想看看我是否可以在默认函数中创建graphql循环:
export default () => {
async function allPosts() {
let data
await graphql(`
query allDitherImages {
prismic {
allProjects(sortBy: meta_firstPublicationDate_DESC) {
totalCount
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
edges {
node {
cover_image
cover_imageSharp {
name
}
}
}
}
}
}
`).then(initialRes => {
data = initialRes
})
return data
}
allPosts().then(result => {
console.log(result)
})
return null
}
但后来盖茨比告诉我Gatsby related 'graphql' calls are supposed to only be evaluated at compile time, and then compiled away. Unfortunately, something went wrong and the query was left in the compiled code.
如何运行多个 graphql 查询?
提前谢谢你:) 迈克尔
【问题讨论】:
-
gatsbyjs.org/docs/data-fetching .... 您可以/应该在 gatsby-node.js 中获取(累积)所有数据(循环中)
标签: graphql gatsby prismic.io