nuxt-modules / sanity

Sanity integration for Nuxt
https://sanity.nuxtjs.org
MIT License
211 stars 35 forks source link

fix: send perspective as query param when using GET method #1008

Closed jesperbjerke closed 1 day ago

jesperbjerke commented 1 month ago

This is the same issue as here: https://github.com/nuxt-modules/sanity/pull/930 but with GET queries. This appends perspective there as well.

netlify[bot] commented 1 month ago

Deploy Preview for nuxt-sanity-module canceled.

Name Link
Latest commit ab51f84188873d66c03cabb6267ca459351500e9
Latest deploy log https://app.netlify.com/sites/nuxt-sanity-module/deploys/66953028712f97000860538b
jesperbjerke commented 1 month ago

Should we just move the query up into fetchOptions?

Hah, good point! Completely missed that 😅 Changed now

jesperbjerke commented 1 month ago

Noticed the RequestInit type doesn't allow for query. And changing it to FetchOptions conflicts with the POST method 🙃 I'll see if I find the correct type to use..

jesperbjerke commented 1 month ago

Actually ... Maybe we need to add it to the qs as &perspective= rather than via query for the get request... Seems like it would produce a double query otherwise.

When I tested it just appended perspective to the existing query params and worked as expected. But I can double check again. What do you mean with "double query" though? 🤔

jesperbjerke commented 1 month ago

Just tested again, both with and without defining perspective in my config. Looks to me as it behaves as expected and just appends the perspective to the existing query params. Perspective defaults to "raw" if not defined.

This is the query params it produces for me: Screenshot 2024-05-31 at 14 56 33

data/query/staging?query=*%5B_type+==+%22article%22+%26%26+language+==+$language+%26%26+slug.current+==+$slug%5D%5B0%5D%7Btitle,+animal_type,+intro,+seo,+body,+image%7D&$language=%22en%22&$slug=%22invaertes-parasiter-hos-kanin-test%22&perspective=previewDrafts