
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe issue you're encountering is a common GROQ gotcha! The problem is that you're trying to dereference the fresh array itself with fresh[]->, but fresh isn't an array of references - it's an array of objects that contain a reference field (ingredienttag).
The -> dereferencing operator only works directly on reference fields, not on objects that contain references. When you use fresh[]->, GROQ tries to dereference each object in the array (not the reference inside it), which fails and returns empty objects.
Here's the solution - you need to project the array without dereferencing it, then dereference the nested reference field:
*[_type == "recipe"]{
_id,
title,
slug,
"dish": dish->{_id, name},
"fresh": fresh[]{
quantity,
unit,
"ingredienttag": ingredienttag->{name}
},
stock,
directions,
"related": related[]->{title},
"book": book->{_id, name, author},
info,
"tag": tag[]->{_id, name, category->{_id, name}}
}The key difference: use fresh[]{} (array projection) instead of fresh[]-> (array dereferencing). Inside the projection {}, you can then dereference the ingredienttag reference field with ingredienttag->{name}.
Why this works:
fresh[] iterates over the array elements{quantity, unit, "ingredienttag": ingredienttag->{name}} projects each object, keeping quantity and unit, and dereferencing the ingredienttag reference to get its nameThis pattern applies whenever you have an array of objects containing references - project the array first with []{}, then dereference the reference fields inside the projection. You can see this pattern in your working queries like "tag": tag[]->{_id, name, category->{_id, name}} where references are dereferenced, but that works because tag is an array of references directly, not an array of objects containing references.
As covered in the GROQ projections documentation, projections let you reshape data and follow references, but the syntax matters depending on your document structure!
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