Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to Add Multiple GROQ Queries to My Nextjs Project

3 replies
Last updated: Jun 18, 2021
I have a homepage page with my Nextjs project. How can i add multiple groq queries for instance 3 blog posts, news posts both type have a name blog and news. How can I combine these 2? without having to call the sanityClient twice for each query? Thanks 🤗
Jun 17, 2021, 10:53 PM
user A
Thank you!😃
Jun 17, 2021, 10:58 PM
user A
How would I apply this to the sanityClieny fetch thanks
Jun 17, 2021, 11:32 PM
Let’s say your fetch normally looks like this (storing in
data
):

client.fetch(`
  *[_type == "blog"][0]
`);
And you serialize your data like this:


<BlockContent blocks={data.content} serializers={serializers} />
Instead, you might query with a fetch like this:


client.fetch(`
  {
    'blog': *[_type == "blog"][0],
    'news': *[_type == "news"][0]
  }
`);
And serialize like this:


<BlockContent blocks={data.blog.content} serializers={serializers} />

<BlockContent blocks={data.news.content} serializers={serializers} />
Jun 18, 2021, 2:05 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?