我需要在一个组件和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 查询?
提前谢谢你:)迈克尔