sanity icon indicating copy to clipboard operation
sanity copied to clipboard

fix: send perspective as query param when using GET method

Open jesperbjerke opened this issue 1 year ago • 5 comments

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.

jesperbjerke avatar May 30 '24 13:05 jesperbjerke

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

netlify[bot] avatar May 30 '24 13:05 netlify[bot]

Should we just move the query up into fetchOptions?

Hah, good point! Completely missed that 😅 Changed now

jesperbjerke avatar May 31 '24 06:05 jesperbjerke

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 avatar May 31 '24 07:05 jesperbjerke

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 avatar May 31 '24 08:05 jesperbjerke

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

jesperbjerke avatar May 31 '24 13:05 jesperbjerke