GraphQL API - Is it Possible to Fetch Draft Content (For Previews)
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 draftspreviewDrafts: Prioritizes draft documents over published versions when both exist - this is what you want for previewsraw: 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
publishedperspective - 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.
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.