sanity-io / gatsby-source-sanity

Gatsby source plugin for building websites using Sanity.io as a backend.
https://www.sanity.io/
MIT License
197 stars 61 forks source link

[Feature Request] Add support for perspectives in plugin options #274

Open fvieira opened 1 year ago

fvieira commented 1 year ago

Is your feature request related to a problem? Please describe. Yes. If I use overlayDrafts, my documents are a mix of drafts and published versions, and the ids reflect this, which makes it impossible to write simple queries like sanityDocument(_id: {eq: "my-document-singleton"}) as this will only fetch the document correctly if it doesn't have a draft version, as otherwise the document id would be drafts.my-document-singleton. As such I have to write the query like this sanityDocument(_id: {regex: "/^(drafts.)?my-document-singleton$/" }) which is way uglier.

Describe the solution you'd like I'd like to be able to pass the perspective as an option to the plugin, so that it ends up in the sanity client. This would allow me to use the previewDrafts perspective instead of overlayDrafts, which results in almost the same result but now no document has drafts. which allows me to write simpler queries. There may be other advantages to supporting perspectives, specially as their functionality grows.