Join live – Get insights, tips, + Q&A from Sanity developers on our latest releases

Discrepancy between post counts in Sanity Vision and local environment using the same query and perspective.

12 replies
Last updated: Oct 27, 2023
Hi 👋 I'm new to Sanity.I set up a groq query like so
*[_type == "post"] { ... }
When I set my Perspective in Sanity Vision to
previewDrafts
it returns 5 results (2 published, 3 drafts).With this

sanityClient({
  // ...
  useCdn: false,
  perspective: isDev ? 'previewDrafts' : 'published'
}) 
and then
console.log(sanityClient.config().perspective)
immediately before I make my groq query, it expectedly logs
previewDrafts
in dev mode....but I only get 2 results...

Why is there a discrepancy between Sanity Vision and my local environment Post counts when they both seem to be using the
previewDrafts
perspective with the same exact query? 🤔
Oct 26, 2023, 10:53 PM
Have you checked that
isDev
is true?
Oct 27, 2023, 6:36 PM
Yeah, for sure.I'm also console.logging
sanityClient.config().perspective
immediately before the groq query gets executed and its
previewDrafts
. 🤷
Oct 27, 2023, 6:59 PM
What API version are you using? Are you passing in a token?
Oct 27, 2023, 7:01 PM
This is in SvelteKit if anyone is familiar with this issue.
I've tried disabling everything that could potentially be caching or server-rendering, so I get the freshest possible data.
Oct 27, 2023, 7:01 PM
I'm using
v2023-10-26
in both Vision and in the Sanity client's config.
Oct 27, 2023, 7:01 PM
I don't think I'm passing a token? I'm not sure what that is. I've got the dataset and other env vars getting loaded in (the Sanity client works to fetch everything else, just the
perspective
in the Sanity client doesn't seem to do anything).
Oct 27, 2023, 7:02 PM
You cannot access drafts in an unauthenticated request.
Oct 27, 2023, 7:03 PM
Ohhh that's probably it.
Oct 27, 2023, 7:06 PM
I'll look into it. Thank you so much
user M
!
Oct 27, 2023, 7:06 PM
You’re welcome! Hope that fixes it!
Oct 27, 2023, 7:08 PM
That was it! Thank you so much again! I was stuck! ❤️
Oct 27, 2023, 7:23 PM
Awesome! Happy coding!
Oct 27, 2023, 7:56 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Categorized in