
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeBased on your excellent troubleshooting, you've identified a real issue that's specific to how the query behaves when executed through the Nuxt Sanity module versus Vision. Let me walk through what's likely happening here.
The key clue is that your query works in Vision but returns empty results for the countries key on the frontend. Given that your query uses count() with a nested subquery containing references(^._id), this is likely related to which documents are being returned by the API.
As documented in the API version 2025-02-19 release, there was a breaking change where the default perspective switched from raw to published. Vision might be using a different perspective than your frontend client, which would explain why:
count() works (it still returns country documents even if the reference check behaves differently)count(*[_type=='network' && references(^._id)]) returns empty (the nested subquery might not be finding references due to perspective differences)Check your Nuxt Sanity module configuration. You'll want to explicitly set the perspective to ensure consistent behavior:
// nuxt.config.ts
export default defineNuxtConfig({
sanity: {
projectId: 'your-project-id',
dataset: 'your-dataset',
apiVersion: '2024-03-15', // or your current version
perspective: 'previewDrafts', // or 'raw' to see all documents including drafts
useCdn: false, // Important: CDN doesn't support all perspectives
}
})Or if you need to set it per-query, you can pass perspective as a parameter to useSanityQuery (check your @nuxtjs/sanity version documentation for the exact syntax).
The references() function checks if documents contain references to a specific ID. When your perspective is set to published, it might not be seeing draft network documents that reference your countries, causing the count() to return 0, which then filters out all countries.
Your troubleshooting confirms this pattern:
count(), the filter isn't excluding anythingCheck what's actually being queried: Add this temporarily to see what's happening:
const query = groq`{
'countries': *[_type == 'country' && (count(*[_type=='network' && references(^._id)]) > 0)],
'countriesDebug': *[_type == 'country']{
_id,
title,
"networkCount": count(*[_type=='network' && references(^._id)]),
"networks": *[_type=='network' && references(^._id)]._id
}
}`Verify your API version: Check which API version your Nuxt Sanity module is using in your config, as different versions have different default behaviors.
Try disabling CDN: If you're using the CDN (useCdn: true), try setting it to false as the CDN may handle complex nested queries differently.
Check the browser network tab: Look at the actual HTTP request being made to the Sanity API to see what URL parameters are being sent (especially perspective).
The fact that removing the object wrapper works suggests there may also be a quirk in how the Nuxt module serializes or processes object-wrapped queries, but the perspective/API version issue is the most likely root cause for why the nested references() check isn't finding the expected documents.
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