Sanity query returns no documents despite data being present in Studio
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:
- Vision tool uses the
rawperspective by default (shows all documents including drafts) - Your client is using the newer API version which defaults to
publishedperspective - Even though you published the documents, there might be a perspective configuration issue
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:
Check the actual API request: Open your browser's Network tab and inspect the actual API request being made. Look at the URL parameters - you should see
?perspective=published(or similar). Compare this to what Vision is using.Test with Vision's perspective: In Vision, there's a perspective dropdown (usually in the top-right). Try switching it to
publishedand see if your documents disappear. If they do, that confirms the perspective issue.Verify document IDs: Use Vision with the
rawperspective and check if your documents havedrafts.prefixes. Even "published" documents might only exist as drafts if something went wrong during publishing:
*[_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.
Check for document-level permissions: If you're using custom access control, verify that your API token has read permissions for these specific documents.
Try a different API version: Temporarily set your client to use
apiVersion: '2021-03-25'to see if the behavior changes (this version defaults torawperspective).
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 thread17 replies
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.