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

Help needed with fetching drafts from referenced documents using groq queries in Slack thread.

3 replies
Last updated: Jul 20, 2023
hii everyone, I need some help fetching drafts from documents referenced within other documents using groq querys, the client is using a raw perspective btw, any help is greatlt appreciated!!

this is my current query

export const regionQuery = (region: string, pre: string) => {
return `*[slug.current == "${region}" && (${pre}(_id in path("drafts.**")))] {
"title": title,
'Points': mapPoints[] -> {
_id,
title,
location,
geoUrl,
geoData,
body,
mainImage,
}
}`;
};

im attaching an example pic of the referenced documents!
Jul 19, 2023, 6:12 PM
Are the points the documents that would be drafts? If so, you’ll need to do a full subquery to get them, as the
->
operator will only get the published version.
Jul 19, 2023, 6:35 PM
thank you so much!! i was hoping to avoid all that, so i solved it using the new perspective option!! it really changes the game
Jul 20, 2023, 12:41 PM
Great!!
Jul 20, 2023, 6:29 PM

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?