Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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

coalesce(
  *[_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.

Contributor

Other schemas by author