🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

Fetch the draft or published version of a document

By Daniel Favand

One query to fetch the draft it it exists, and fall back to the published version of a document.

GROQ query

  *[_id == 'drafts.' + $documentId][0], 
  *[_id == $documentId][0]

This query uses the coalesce GROQ function to resolve the draft version of a document, and if it doesn't exist, fall back to the published version.

Be sure to supply a documentId as a parameter for the query.


Other schemas by author