GraphQL API - Is it Possible to Fetch Draft Content (For Previews)

2 replies
Last updated: Apr 29, 2020
Hi all, is it possible to fetch draft content (for previews, using
resolveProductionUrl
) when querying with the GraphQL API?
AI Update

Yes! It is possible to fetch draft content with the GraphQL API for previews. You can use the perspective query parameter to control which version of your content is returned.

Using Perspectives with GraphQL

To fetch draft content, add the perspective query parameter to your GraphQL endpoint. The available options are:

  • published (default): Returns only published documents, excluding drafts
  • previewDrafts: Prioritizes draft documents over published versions when both exist - this is what you want for previews
  • raw: Returns both drafts and published content side-by-side (requires authentication)
  • Perspective stack: You can pass a comma-separated list for content releases (e.g., releaseA,releaseB,published)

Example for Preview/Draft Mode

For your resolveProductionUrl preview use case, you'd query the GraphQL API like this:

https://<yourProjectId>.apicdn.sanity.io/v2025-02-19/graphql/<dataset>/<tag>?perspective=previewDrafts

The previewDrafts perspective will return draft versions when they exist, falling back to published versions when no draft is available - perfect for preview environments where editors need to see their unpublished changes.

Important Notes

  • The perspective parameter works with both the API (api.sanity.io) and API CDN (apicdn.sanity.io) endpoints
  • For production, stick with the default published perspective
  • Draft documents in Sanity have IDs prefixed with drafts. (e.g., drafts.post-123)
  • You can read more about Perspectives in the Sanity docs

This feature is available in GraphQL API version v2023-08-01 and later, including the current v2025-02-19.

The filters has a
is_draft
options, but that requires an authenticated request: https://www.sanity.io/docs/graphql#filters-c7d336bd9658
awesome, thanks!

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?