Using groq is there a way to resolve all references inside your data no matter how deep?
Unfortunately, GROQ doesn't have built-in recursive dereferencing - there's no automatic way to resolve all references at any depth without manually specifying each level. The reference access operator (->) in GROQ only resolves one level at a time.
This means if you have nested references (a document references another document that references another), you need to explicitly chain the -> operator for each level:
*[_type == "article"] {
title,
author->, // Resolves 1 level
author->{ // Resolves 2 levels
name,
department->
},
author->{ // Resolves 3 levels
name,
department->{
name,
manager->
}
}
}Why This Limitation Exists
GROQ is designed this way for good reasons:
- Performance: Recursive resolution could create expensive queries that cascade through many documents
- Circular references: Without depth limits, circular references (A → B → A) would cause infinite loops
- Intentional data modeling: It encourages you to think about what data you actually need
Practical Workarounds
1. Resolve what you need in your query
Be explicit about the depth you need for each use case:
*[_type == "event"] {
title,
venue->{
name,
location
},
speakers[]->{
name,
company->{ name }
}
}2. Handle additional resolution client-side
Fetch the data with some references resolved, then make additional queries for deeper data if needed. This gives you more control over loading states and performance.
3. Denormalize strategic data
For frequently accessed nested data, consider duplicating it at query time or storing computed values. You could use Sanity Functions to maintain denormalized data when documents change.
4. Use projections to limit payload size
When you do resolve references, use projections to only fetch the fields you need rather than entire documents:
*[_type == "post"] {
title,
"authorName": author->name,
"categoryTitle": category->title
}While it would be convenient to have automatic deep dereferencing, the manual approach gives you better control over query performance and helps you think intentionally about your data structure. The key is to resolve references to the depth your UI actually needs, not necessarily all possible references.
Show original thread4 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.