Open Designer023 opened 1 week ago
Looks like I have figured this out:
Create a query first
const articleFeed = q("").grab({
articles: q("*")
.filterByType("article")
.grab({
title: q.string()
})
})
Then we can use it, and as a bonus we can use the schema too:
{
"_type == 'articleFeed'":
[
articleFeed.query,
articleFeed.schema
]
}
Is there an existing issue for this?
Code of Conduct
Question
This is a bit of a strange question, but I have a schema where I have an array of types, so that I can use it as a page builder kind of thing:
There are more types than in the code, but this is just an example.
I can query each of these in my parent schema using something like:
I can successfully get the
articleFeed
data back here, but what I would like to do is to, instead of@
do a "sub query" for a feed of articles. I have managed to do this by replacing the@
with a raw query, but is there any way I can make this into a groqd query, so that it's cleaner and more robust?Bonus
Is it conceivably possible to use a value from the articleFeed, such as
count
ortag
so that the article feed can be configured from the sanity CMS?I'm not worried about if the query is slow as this is a build-time query and won't be run very often