
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou're not losing your mind! This is a common GROQ challenge when working with mixed arrays containing both references and regular objects. The issue is that when you use the dereference operator (->), it only works on reference items and filters out non-references.
Here's the solution: use a projection with conditional dereferencing to handle both types:
submenuItems[] {
_type == 'reference' => @->,
_type != 'reference' => @
}Or more explicitly:
submenuItems[] {
...,
_type == 'reference' => {
"item": @->
},
_type != 'reference' => {
"item": @
}
}What's happening here:
[] operator iterates through your array=> checks each item's type@-> dereferences them (the @ refers to the current item)@ just returns them as-isA cleaner approach if you want to flatten the structure:
submenuItems[] {
_type == 'reference' => @->{
// explicitly select fields from the referenced document
_id,
title,
slug
},
_type != 'reference' => {
// return the URL object as-is
...
}
}Pro tip: If your URL items have a specific _type (like urlLink), you can be even more specific:
submenuItems[] {
_type == 'reference' => @->,
_type == 'urlLink' => @
}This pattern works because GROQ evaluates each conditional in order and returns the first match. Your non-reference siblings will stay intact while references get expanded. No more missing menu items!
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