
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeUnfortunately, no, GROQ does not support automatically resolving all references without specifying fields. The dereference operator (->) requires you to explicitly indicate which fields you want from referenced documents.
GROQ is designed to be explicit about data fetching. When you use the -> operator, you need to either:
*[_type == "event"] {
venue->{
name,
address
}
}*[_type == "event"] {
venue->{
...
}
}However, even with spread operators, you'd need to manually traverse nested references and specify fields at each level. There's no "resolve everything recursively" option in GROQ itself.
For your specific Gatsby preview scenario, you're trying to mirror what GraphQL does automatically. The good news is that gatsby-source-sanity has a solution: the _raw fields with resolveReferences.
According to the gatsby-source-sanity documentation, the plugin generates special _raw fields that can automatically resolve references:
{
allSanityProject {
edges {
node {
_rawTasks(resolveReferences: {maxDepth: 5})
}
}
}
}The key options here:
_raw<FieldName>: These fields contain the raw JSON data from SanityresolveReferences: When enabled with a maxDepth, this will automatically traverse and resolve references within the raw field datamaxDepth: Controls how many levels deep to resolve references (prevents infinite loops)For your document-by-ID query with full reference resolution:
query PreviewQuery($id: String!) {
sanityYourType(_id: {eq: $id}) {
_id
_type
_rawBody(resolveReferences: {maxDepth: 10})
_rawExcerpt(resolveReferences: {maxDepth: 10})
# Add _raw versions of any other fields that might contain references
}
}This approach:
_raw fields are Gatsby-specific: They're generated by gatsby-source-sanity and won't work in Sanity's GraphQL playgroundresolveReferences: {maxDepth: N} to each _raw fieldmaxDepthIf _raw fields don't meet your needs, you'd need to construct multiple GROQ queries or use GROQ's projection syntax with explicit field listing—there's simply no automatic "give me everything with all references resolved" option in GROQ itself. The GROQ reference access operator always requires you to specify what you want from the referenced document.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store