Issue with reference fields not returning expected data in GROQ query.
I can see your query syntax industries[]->{title} is actually correct GROQ! The issue is with how conditional projections work within nested array projections.
The problem is that when you use _type == 'industries' => {...} inside an array projection, the conditional completely replaces the object when true. Without the spread operator (...), you only get back what you explicitly define in that conditional block, which is why you're seeing just _ref, _key, and _type without the dereferenced titles.
Here's the corrected query:
*[_type == "landingPage" && slug.current == "get-started"][0]{
landingPageBuilder[] {
_type == 'industries' => {
...,
industries[]->{title}
}
}
}Why this works:
- The spread operator (
...) preserves all the original fields from the landingPageBuilder item - Your syntax
industries[]->{title}is valid GROQ - it dereferences each reference in the array and projects only the title field - According to the GROQ joins documentation, the pattern
array[]->{fields}correctly dereferences arrays of references with projection
Alternative if you only need title strings:
If you want a flat array of title strings instead of objects with title properties:
*[_type == "landingPage" && slug.current == "get-started"][0]{
landingPageBuilder[] {
_type == 'industries' => {
...,
"industries": industries[]->title
}
}
}Note the difference: industries[]->title (without curly braces) gives you ["Title 1", "Title 2"], while industries[]->{title} gives you [{title: "Title 1"}, {title: "Title 2"}].
The key takeaway: conditional projections inside array projections need the spread operator to preserve existing fields, otherwise you only get what you explicitly project in the conditional block. Your dereference syntax was correct all along!
Sanity – Build the way you think, not the way your CMS thinks
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.