Joint session with Vercel: How to build intelligent storefronts (May 15th)

Select draft OR published document

Setting up a live preview and want to fetch a document's draft, with a fallback for the published document when there are no drafts? Check this out.

By Formidable


Draft with published document fallback

*[_type == 'pokemon' && slug.current == "bulbasaur"]
  | score(_id in path("drafts.**"))
  | order(_score desc)[0]

When building out live previews, you generally want to fetch draft documents. However, if there are no drafts available for the document you're editing – you want to fall back to the currently-published version of the document.

This query is an example of how to do this using GROQ's `score` and `order` functions.

Contributor

Formidable

We build the modern web.

Visit Formidable's profile