
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeLooking at your query, you're very close! The syntax you're trying to use is correct - conditional projections with the _type == 'value' => pattern is indeed the right approach for querying arrays with multiple document types.
Based on the example from the Query Cheat Sheet, here's the correct syntax:
*[_type == "resourcesPage"][0] {
mainHeading,
subHeading,
bodyText,
resourceItems[]-> {
_type == "youTube" => {
_type,
title,
url,
description,
thumbnail
},
_type == "blogPost" => {
_type,
title,
summary,
mainImage,
author->{ name, avatar },
"tags": tags[]-> tagName,
"slug": slug.current
}
}
}The key points about conditional projections:
->) to follow the references first: resourceItems[]->_type == 'value' => { fields }This approach is much cleaner than:
The conditional projection syntax gives you exactly what you need: an array of mixed document types, each with their own specific fields, in the original order. This is part of GROQ's projection features that allow you to transform and reshape data based on conditions.
If you're getting null as a result, double-check that:
resourceItems array actually contains references (has _ref values)_type values you're checking for-> correctlyYou can test this step-by-step in Vision by first querying just resourceItems[]-> to see what the dereferenced documents look like, then adding the conditional projections.
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