Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
How to execute all queries in graphql inside gatsby-node.js?

I want to execute multiple queries nodes at the same time in gatsby-node.js in order to create pages accordingly to my query , so these are the queries :

{
      allPrismicLastPosts {
        nodes {
          data {
            blogs {
              blog {
                document {
                  ... on PrismicBlog {
                    uid
                  }
                  ... on PrismicCulture {
                    uid
                    }
                  }
                }
              }
            }
          }
        }
      }
      allPrismicMainBlogs {
        nodes {
          data {
            blogs {
              blog {
                document {
                  ... on PrismicBlogMain {
                    uid
                  }
                }
              }
            }
          }
        }
      }
}

So in order to createPage in gatsby-node.js I need both the uid of allPrismicLastPosts and allPrismicMainBlogs from these queries , this is what I 've tried :

{
      allPrismicLastPosts {
        nodes {
          data {
            blogs {
              blog {
                document {
                  ... on PrismicBlog {
                    uid
                  }
                  ... on PrismicCulture {
                    uid
                    }
                  }
                }
              }
            }
          }
        }
      }
      allPrismicMainBlogs {
        nodes {
          data {
            blogs {
              blog {
                document {
                  ... on PrismicBlogMain {
                    uid
                  }
                }
              }
            }
          }
        }
      }
}

But this will only fetch the allPrismicLastPosts uid instead I want all the uid ,Any idea to solve this ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have many ways of doing this. The easiest one is to assign each result of the query to a variable like:

const posts = await graphql(`
  query {
    allPrismicLastPosts {
      nodes {
        data {
          blogs {
            blog {
              document {
                ... on PrismicBlog {
                  uid
                }
                ... on PrismicCulture {
                  uid
                }
              }
            }
          }
        }
      }
    }
  }
`);
const mainBlog = await graphql(`
  query {
    allPrismicMainBlogs {
      nodes {
        data {
          blogs {
            blog {
              document {
                ... on PrismicBlogMain {
                  uid
                }
              }
            }
          }
        }
      }
    }
  }
`);

Then you just need to loop through each variable:

  posts.data.allPrismicLastPosts.nodes.forEach(node => {
    createPage({
       // your data here
      }),
  });

  mainBlog.data.allPrismicMainBlogs.nodes.forEach(node => {
    createPage({
       // your data here
      }),
  });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!