How to globally ignore drafts in GROQ queries without filtering each time?

11 replies
Last updated: Jan 24, 2026
Is there a way to ignore all drafts and not have to
!(_id in path('drafts.**'))
in every groq requests?
AI Update

Yes! You can use perspectives to control whether drafts are included in your queries without adding !(_id in path('drafts.**')) to every GROQ request.

The easiest solution is to set the perspective parameter to published when making your API requests. The perspectives feature provides different views of your content:

  • published - Returns only published documents (no drafts)
  • previewDrafts - Returns drafts when they exist, falling back to published versions
  • raw - Returns everything (both drafts and published documents)

How to use perspectives

In client configuration:

import {createClient} from '@sanity/client'

const client = createClient({
  projectId: 'your-project-id',
  dataset: 'production',
  useCdn: true,
  apiVersion: '2025-02-19',
  perspective: 'published' // This filters out drafts automatically
})

In individual queries:

const data = await client.fetch(
  `*[_type == "post"]`,
  {},
  {perspective: 'published'}
)

In HTTP API requests:

https://your-project.api.sanity.io/v2025-02-19/data/query/production?query=*[_type=="post"]&perspective=published

Important note about API versions

If you're using the API version 2025-02-19 or later, the default perspective changed to published, so you'll automatically get only published documents without any additional configuration. In older API versions, the default was raw, which includes both drafts and published documents.

This is much cleaner than manually filtering drafts in every query, and it gives you flexibility to switch between perspectives based on your environment (e.g., use previewDrafts for preview environments and published for production).

Show original thread
11 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.

Was this answer helpful?