Fetching draft documents with DocumentFilter is_draft:true outside GraphQL playground
Yes, there are people who have successfully fetched data with DocumentFilter is_draft: true from the GraphQL API outside the playground, but they've encountered a significant limitation with nested draft documents.
Based on community discussions, the is_draft filter works well for top-level documents:
allPage(limit: 1, where: {_: { is_draft: $isDraft }, slug: { current: { eq: $slug } } }) {
title
slug { current }
}However, the major issue is with referenced documents. When you have nested documents (references) in your content, the GraphQL API returns the published versions of those references, not the drafts - even when the parent document is fetched as a draft.
The GraphQL documentation confirms that filters like is_draft are available under the _ field, but it doesn't provide a way to filter nested references in GraphQL queries.
The Solution: Use GROQ Instead
Many developers who hit this limitation have switched to GROQ for draft previews. With GROQ, you can fetch draft versions of nested references using the coalesce() function:
*[_type == "page" && slug.current == $slug && _id in path($idMatch)][0] {
_id,
title,
slug,
'placeholderContent': placeholderContent[] {
...coalesce(
*[_id in ["drafts." + ^._ref]][0],
*[_id in [^._ref]][0]
)
}
}This pattern checks for the draft version first (drafts.** prefix), then falls back to the published version if no draft exists.
Alternative: Use Perspectives
Another approach is to use Sanity's Perspectives feature with the GraphQL API. With the previewDrafts perspective, you can query content as if drafts were published:
# Set perspective parameter to 'previewDrafts' in your API request # https://YOUR_PROJECT_ID.api.sanity.io/vX/graphql/YOUR_DATASET/default?perspective=previewDrafts
However, note that with API version 2025-02-19, the default perspective changed from raw to published, so you'll need to explicitly set the perspective parameter.
Bottom line: While the GraphQL is_draft filter works for top-level documents, it has limitations with nested references. For comprehensive draft preview functionality including nested content, GROQ is currently the most robust solution, though using the previewDrafts perspective with GraphQL may also work depending on your use case.
Show original thread5 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.