
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes! You can resolve references within PortableText arrays using the @ operator combined with conditionals. The @ operator refers to the root value of the current scope, which is perfect for handling mixed content where some items are references and others aren't.
Here's the pattern you'll want to use:
*[_type == "yourDocType"] {
content[]{
...,
_type == 'yourReferenceType' => {
'resolved': @->
}
}
}For example, if you have a PortableText array with custom reference blocks mixed with regular text spans, you can do:
{
"content": content[]{
...,
_type == 'orderReceiptPlaceholderRef' => {
'referenceData': @->
}
}
}The key points:
@-> instead of just -> - The @ operator targets the current item in the array iteration, then -> dereferences it... (spread operator)'referenceData': @->This approach works because:
children[]-> would try to dereference everything, leaving non-references as nullchildren[] alone includes everything but doesn't resolve references@-> selectively resolves only the reference types while preserving everything elseYou can find more details about GROQ conditionals in the query cheat sheet and learn about the reference access operator (->) in the GROQ joins specification.
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