Join live – Get insights, tips, + Q&A from Sanity developers on our latest releases

Ok I figured it out... holy crap GROQ is amazing. I still love GQL for what it is, but I think GROQ is the best thing since bread, sliced or otherwise.

1 replies
Last updated: Dec 20, 2020
Ok I figured it out... holy crap GROQ is amazing. I still love GQL for what it is, but I think GROQ is the best thing since bread, sliced or otherwise.
Dec 20, 2020, 6:32 PM
For anyone who's interested, here's the query:
export const getCats = `// groq
    *[_type == "category"]{
        _id, name, slug,
        "products": *[_type == "product" && references(^._id)]{
             _id, name, slug
        } | order(_createdAt desc)[0..4]
    }
`
Dec 20, 2020, 6:48 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?

Categorized in