
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your query, the issue is that you're trying to filter on the reference objects themselves before dereferencing them. In GROQ, you need to filter after dereferencing to access the properties of the referenced documents.
Here are a few approaches to solve this:
*[_id == "allRecipesPage"]{
editorsPicks {
"recipes": recipes[]-> {
${recipeTeaserGroq}
}[!defined(releaseDate) || releaseDate <= $currentDate],
},
}The key is moving the filter to after the -> dereference operator. This way you're filtering on the actual recipe documents, not the reference objects.
*[_id == "allRecipesPage"]{
editorsPicks {
"recipes": recipes[]->{
${recipeTeaserGroq}
}[!defined(releaseDate) || releaseDate <= $currentDate],
},
}This is essentially the same as Option 1 - the filter [!defined(releaseDate) || releaseDate <= $currentDate] is applied to the dereferenced results.
*[_id == "allRecipesPage"]{
editorsPicks {
"recipes": recipes[]._ref in *[
_type == "recipeArticle"
&& (!defined(releaseDate) || releaseDate <= $currentDate)
]._id => recipes[]->{
${recipeTeaserGroq}
},
},
}Option 1 or 2 are the cleanest approaches - just dereference first with ->, then apply your filter to the dereferenced documents. The filter sees the full recipe document properties after the dereference happens.
The pattern is: array[]->{projection}[filter] where the filter operates on the dereferenced documents, not on the reference objects themselves. This is documented in the Query Cheat Sheet under the "Joins" and "Object Projections" sections.
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