I want to createPage based on some queries I am using , this is my query in my gatsby-node.js :
{
allPrismicLastPosts {
nodes {
data {
blogs {
blog {
document {
... on PrismicBlog {
uid
}
... on PrismicCulture {
uid
}
}
}
}
}
}
}
}
allPrismicMainBlogs {
nodes {
data {
blogs {
blog {
document {
... on PrismicBlogMain {
uid
}
}
}
}
}
}
}
}
what I want from this query is the uid field ,
and Since this query returns this JSON format :
allPrismicMainBlogs": {
"nodes": [
{
"data": {
"blogs": [
{
"blog": {
"document": {
"uid": "main02",
.
.
.
}
I've tried this to fetch the uid :
postPages.data.allPrismicLastPosts.nodes.forEach((page) => {
page.data.blogs.forEach((article)=>
{
createPage({
path: article.blog.document.data.uid,
component: path.resolve(__dirname, 'src/templates/post.js'),
context: {
id: page.id,
},
})
}
)
})
I cannot get the uid because I am using allPrismicLastPosts but instead I want all the queries , so how can I fix this to display all the uid
I think you are trying to access directly to:
article.blog.document.uid
Applied to your code:
postPages.data.allPrismicLastPosts.nodes.forEach((page) => {
page.data.blogs.forEach((article) => {
createPage({
path: article.blog.document.uid,
component: path.resolve(__dirname, "src/templates/post.js"),
context: {
id: page.id,
},
});
});
});