Reusable GROQ query strings in Next.js app
*[_type == "blogPost" && slug.current == "${blogPostSlug}"]{
_id,
title,
author->{
name,
slug{ current },
bio,
authorImage{ asset->{path, url} }
},
body[]{
_type == 'blogImageRef' => @->{
caption,
image{
asset->
},
imageTags
},
_type == 'imageCollectionRef' => @->{
_id,
collectionName,
collectionImages[]->,
},
_type != 'reference' => @,
},
categories[]->{ title, description, slug{ current } },
excerpt,
location->{ locationName, mapLocation },
mainImage->{_createdAt, caption, image{ asset->{ path, url } }, author->{ name, slug } },
publishedAt,
slug{ current },author->{
name,
slug{ current },
bio,
authorImage{ asset->{path, url} }
}${unpackAuthorRef}https://github.com/sanity-io/hydrogen-sanity-demo/blob/main/src/fragments/sanity/portableText/portableText.ts
https://www.sanity.io/docs/community-code-of-conduct#c6090fc307bc
“This includes memes, emojis, and GIFs. And remember, we’re not only “guys” – including us at Sanity HQ – (we are people, folks, friends, y’all, etc).”
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.