Joint session with Vercel: How to build intelligent storefronts (May 15th)

Sanity query returns no documents despite data being present in Studio

17 repliesLast updated: Nov 30, 2025

I’m having an issue where data is not being returned from a query that is present in our studio. The vision tool returns the data properly from within the studio. When using the sanity client however, no documents are returned for the given type. I confirmed both the project ID and dataset are correct. Is there any way to debug this further? I don’t seem to be getting any error messages or anything of that sort. I also confirmed with a
*
query to return all possible documents and attempted to filter it using javascript rather than the query, the documents are still not present so it does not appear to be an issue with the query. In both dev and deployed environments, the data is present in the studio. Other documents and data types other than this one are returned properly. I confirmed the documents are published. I have edited various documents of this type multiple times from different deploys and re-published them to no avail. Also confirmed that useCdn is set to false. Generated a fresh API key, still persists. Confirmed it is in the CORS URLs as well. No console errors in either studio or page that attempts to retrieve data.
AI Update

This sounds like a classic API perspective mismatch issue. Since Vision returns your documents but your client doesn't, and you've confirmed the documents are published, the most likely culprit is the API perspective setting.

The Root Cause: API Version Default Change

If you're using API version v2025-02-19 or later, the default perspective changed from raw to published. This is a breaking change that catches many developers off guard.

Here's what's likely happening:

How to Fix It

Option 1: Explicitly Set the Perspective in Your Client

Add the perspective parameter to your client queries:

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  apiVersion: '2025-02-19',
  useCdn: false,
  perspective: 'raw', // or 'previewDrafts' or 'published'
})

Or set it per-query:

const result = await client.fetch(query, params, {
  perspective: 'raw'
})

Option 2: Check Your API Version

If you're using an older API version string in your client config (like '2021-03-25'), try updating to the latest version and explicitly setting the perspective.

Additional Debugging Steps

Since you've already ruled out many common issues, try these:

*[_type == "yourType"] { _id, _type }

Look for IDs like drafts.document-id vs document-id. If you only see the drafts. versions, that's your problem - they were never actually published, just saved as drafts.

Why This Happens

Sanity uses perspectives to provide different views of your content. The published perspective only returns documents without the drafts. prefix, while raw returns everything. If there's any inconsistency in how your documents were published, or if you're comparing different perspectives, you'll see this exact symptom.

The fact that other document types work fine suggests this particular type might have publishing workflow issues or was created/modified in a way that affected its published state differently.

The Quick Test

Add this to your client code and see if your documents appear:

const result = await client.fetch(
  '*[_type == "yourType"]',
  {},
  { perspective: 'raw' }
)

If they show up with perspective: 'raw' but not with perspective: 'published', you've confirmed the issue - your documents exist only as drafts despite appearing published in the Studio.

Show original thread
17 replies

Was this answer helpful?

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.

Related contributions