Ayyash
Posted on February 26, 2022
To retrieve the results and the total, using GROQ for Sanity.IO, you need to start by casting to your model like this (this is passed in query)
query = `{
"items": *[_type == "post"] | order(publishedAt desc)[1...5],
"total": count(*[_type == "post"])
}`
The result looks like this
{
"ms": 65,
"query": "...",
"result": {
"items": [
{...}
],
"total": 34
}
}
It looks obvious, but I had to read How Queries Work all the way to the end to figure out I can project my own outside model. Hope this helps someone.
RESOURCES
💖 💪 🙅 🚩
Ayyash
Posted on February 26, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.