Learning GROQ and querying in Sanity.io can be confusing, but there are helpful resources available.
3 replies
Last updated: Aug 10, 2021
D
How would I be able to query that? I'm just learning this and its sort of confusing me
Aug 10, 2021, 2:42 AM
G
Hi Douglas! I agree that getting started with GROQ can be confusing. Please reach out if you’re interested in some resources—Henrique’s Learn GROQ in 45 Minutes and the Kap & Lauren Learn GROQ video series are two that initially come to mind. For your query, here’s how I would build it (only the final query is relevant—the rest are just steps to get there—but you should be able to test the intermediary queries in Vision to see what’s returned and infer how you could take the query from there):
• Since queries work left-to-right, you’ll start by getting the documents you want by querying for everything (
*
) that has a
_type
of
post
.
*[_type == post]
• This query will return all the properties that exist on each post, including your array,
categories
. However, each of those
categories
will be an array of
_type
and
_ref
properties. Since you want to see the contents of those
I hope this helps explain queries a bit. If anything isn’t working or is still confusing, please follow up. Otherwise, have fun building with GROQ and Sanity.
Aug 10, 2021, 3:13 PM
D
Thank you so much for the comprehensive response.What a phenomenal help!
Aug 10, 2021, 4:16 PM
D
Thank you so much for the comprehensive response.What a phenomenal help!