
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see the issue with your query! The problem is with the syntax countries[].country->. The .country part is trying to access a property, but you're using it before the dereference operator, which won't work correctly.
Based on the GROQ reference access operator documentation, when you have an array of references, you need to apply the dereference operator directly to each item in the array.
Your query should look like this:
*[_type == "post" && slug.current == 'hello-world'] | order(_updatedAt desc) {
title,
'test': countries[]->{ title, slug }
}The key difference is countries[]-> instead of countries[].country->.
Why this works:
countries[] iterates through each item in the array-> dereferences each reference (following the _ref to fetch the actual document){ title, slug } projects only the fields you want from each referenced country documentIf your schema actually has a nested structure where each array item has a country property that contains the reference (like {country: {_ref: "..."}} rather than just {_ref: "..."}), then you'd need:
'test': countries[].country->{ title, slug }But in that case, make sure your schema actually has that intermediate country object. Most commonly, arrays of references are structured as direct references without an intermediate property, which is why the first syntax should work.
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