Formidable
We build the modern web.
Formidable is located at North America, UK & EMEA
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.
*[_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.
We build the modern web.