Querying a schema returns an empty array after breaking website into multiple pages.

3 replies
Last updated: Aug 22, 2023
i dont know why am having an empty array after querying a schema, and in my studio i have two items i was working before when my website was a single page but now am breaking it to multiple pages, thats when i started getting this error
AI Update

This is almost certainly caused by the recent API version 2025-02-19 breaking change where the default perspective switched from raw to published.

When you query Sanity, you're now getting only published documents by default, but the two items you see in Studio are likely still in draft state (unpublished). In Studio, you see both drafts and published documents, which is why they appear there but not in your query results.

Here's how to fix it:

Option 1: Set perspective to previewDrafts (recommended for development)

If you're using a Sanity client, add the perspective parameter:

import { createClient } from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'your-dataset',
  useCdn: false, // set to false when using previewDrafts
  apiVersion: '2025-02-19',
  perspective: 'previewDrafts' // This will return published docs or drafts if no published version exists
})

Option 2: Set perspective to raw

If you want the old behavior (all documents including both drafts and published):

const client = createClient({
  // ... other config
  perspective: 'raw'
})

Option 3: Publish your documents

In Sanity Studio, click the "Publish" button on your two documents. Once published, they'll appear in queries using the default published perspective.

The API version 2025-02-19 introduced this breaking change because Sanity added Content Releases, and most production sites should only query published content by default.

For development/preview environments, use perspective: 'previewDrafts'. For production, use the default published perspective and make sure your content is published in Studio.

Is the name of your document
product
or
products
? If it is the former, your query should be:
*[_type == 'product']{
  ...,
}
yes it is, totally skipped my mind. thanks so much is working now
product

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.

Was this answer helpful?