Help with GROQ
Hey! Happy to help you with GROQ! It's Sanity's query language for working with content, and once you get the hang of it, it's really powerful.
What is GROQ?
GROQ (Graph-Relational Object Queries) is Sanity's open-source query language designed specifically for filtering, fetching, projecting, joining, and transforming JSON documents from your Content Lake. Think of it as a way to ask for exactly the content you need, shaped exactly how you want it.
Basic Structure
The fundamental pattern of a GROQ query looks like this:
*[filter]{projection}*= all documents (that you have permission to read)[filter]= which documents you want (optional){projection}= how to shape the results (optional)
Quick Example
Here's a practical example that fetches directors born since 1970 with their movies:
*[_type == "director" && birthYear >= 1970]{
name,
birthYear,
"movies": *[_type == "movie" && director._ref == ^._id]
}Key Things to Know
It's a JSON superset: If you know JSON, you already understand part of GROQ's syntax. Any valid JSON is a valid GROQ query.
Pipeline-based: GROQ queries work as pipelines where results flow through each component. You can chain filters and projections together.
Whitespace doesn't matter: Format your queries however you like. You can also add comments with //.
Learning Resources
Sanity has great resources to help you learn:
- Vision Plugin - Test queries right in Studio
- GROQ syntax documentation - Full reference
- Sanity Learn - Courses specifically on GROQ
- spec.groq.dev - The full open-source specification
What specific aspect of GROQ are you trying to work with? The basics above should get you started, but there's a lot more depth available depending on what you're building!
Show original thread61 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.