✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Issue with data not being returned from query in Sanity Studio

17 replies
Last updated: Jan 11, 2023
I’m having an issue where data is not being returned from a query that is present in our studio. The vision tool returns the data properly from within the studio. When using the sanity client however, no documents are returned for the given type. I confirmed both the project ID and dataset are correct. Is there any way to debug this further? I don’t seem to be getting any error messages or anything of that sort. I also confirmed with a
query to return all possible documents and attempted to filter it using javascript rather than the query, the documents are still not present so it does not appear to be an issue with the query. In both dev and deployed environments, the data is present in the studio. Other documents and data types other than this one are returned properly. I confirmed the documents are published. I have edited various documents of this type multiple times from different deploys and re-published them to no avail. Also confirmed that useCdn is set to false. Generated a fresh API key, still persists. Confirmed it is in the CORS URLs as well. No console errors in either studio or page that attempts to retrieve data.
Jan 10, 2023, 11:41 PM
If i attempt to run the query from the command line I get an error:
Error: Failed to run query:
An unexpected error occurred
    at Object.action (~/****/node_modules/sanity/lib/_chunks/_internal-ca5bebdb.js:1491:13)
Which is also no help. This is node v18.12.1
Jan 10, 2023, 11:51 PM
I get this error on both our staging and production datasets
Jan 10, 2023, 11:54 PM
ok, running the query from the studio directory resolves the error and returns the data correctly
Jan 11, 2023, 12:01 AM
the error was previously a 500 internal server error
Jan 11, 2023, 12:01 AM
the sanity client still does not return the data however in our web app
Jan 11, 2023, 12:01 AM
confirmed this issue on a separate dev machine as well to rule out local configuration
Jan 11, 2023, 12:11 AM
Given that other data shows up, what’s most likely happening is the documents are drafts and your client is not picking up on the token you’re providing. If you’re using an env to obscure your token, I’d start by checking there.
It could also be that your client is using a different API version than the one that Vision uses. If you haven’t specified an API version, your client will default to
, which is lacking features of
(which is what Vision defaults to).
Jan 11, 2023, 12:17 AM
If you’re using an env to obscure your token, I’d start by checking there.
I’m not sure where the token actually comes into play here now that I’m looking more closely. The data is retrieved server side and I set up the client according to this: https://www.sanity.io/docs/connect-your-content-to-next-js
Jan 11, 2023, 12:20 AM
I set both vision and the client to
Jan 11, 2023, 12:20 AM
and verified that vision still returns the correct results
Jan 11, 2023, 12:21 AM
Also when I tested the CLI I set this version using the
Jan 11, 2023, 12:21 AM
I confirmed that the documents are not drafts also - I edited a few and re-published them. All of them appear to be published to begin with
Jan 11, 2023, 12:21 AM
ok so adding a
property to the API config did return the documents now. But why weren’t they there before if they are published?
Jan 11, 2023, 12:24 AM
OK got it - the person that imported this data put dots in the IDs
Jan 11, 2023, 12:25 AM
I believe that is the issue at least?
Jan 11, 2023, 12:27 AM
Ah, yes. If a document is on a non-root path (like
or anything else with a
) it will only be queryable if you make an authenticated request.
Jan 11, 2023, 12:35 AM
ok thanks for the clarification
Jan 11, 2023, 1:08 AM

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?