Updating API version causes empty results, resolved by changing query syntax
10 replies
Last updated: Oct 28, 2021
A
Hello, we just updated the API version and some of our queries, like the following, are returning empty results. Is there a list of changes to the API somewhere? There is the general change log that I can try to dig through if not.
This is the query:
This is the query:
*[(_type== 'event' || _type== 'news' || _type== 'resource') &&categories[]._ref == '${category}'][0...12] { ... }
Oct 28, 2021, 3:26 PM
A
in this case ${category} is a document id that we have
Oct 28, 2021, 3:29 PM
A
Oct 28, 2021, 3:54 PM
W
We were able to verify that changing from
==to
ingets the expected results.
*[(_type== 'event' || _type== 'news' || _type== 'resource') && "898fcc4d-1562-4aeb-923a-6fccf4682e78" in categories[]._ref][0...12] { ... }
Oct 28, 2021, 3:59 PM
W
Would be nice to see the docs where this syntax is specified.
Oct 28, 2021, 4:00 PM
I’m glad you got things working! 🙌
The exact syntax is the second example in the code block
here , but a clearer example specific to this use case is a good idea. I’ll add something on that page. Is there anywhere else you looked in the docs that didn’t offer a solution and you think it should?
The exact syntax is the second example in the code block
here , but a clearer example specific to this use case is a good idea. I’ll add something on that page. Is there anywhere else you looked in the docs that didn’t offer a solution and you think it should?
Oct 28, 2021, 4:23 PM
A
I think the cheatsheet may have been the source of some confusion
Oct 28, 2021, 4:24 PM
W
These examples were the ones that lead us to that approach.
*[count((categories[]->slug.current)[@ in ["action", "thriller"]) > 0] *[castMembers[].person._ref == 'person_sigourney-weaver'] // Any document having a castMember referencing sigourney as its person
Oct 28, 2021, 4:39 PM
W
These examples were the ones that lead us to that approach.
*[count((categories[]->slug.current)[@ in ["action", "thriller"]) > 0] *[castMembers[].person._ref == 'person_sigourney-weaver'] // Any document having a castMember referencing sigourney as its person
Oct 28, 2021, 4:39 PM
Thank you, Wayne. I’ve corrected the sigourney-weaver example on the cheat sheet as the
There’s also a Gotcha added
here that attempts to clarify
Feel free to give any feedback. Or, if you see any other pages that might be worthy of this being mentioned, please let me know. Thanks again!
==example would only work on
v1. It now uses
in, which works on all GROQ versions.
There’s also a Gotcha added
here that attempts to clarify
==vs.
inwhen comparing a string against an array of strings.
Feel free to give any feedback. Or, if you see any other pages that might be worthy of this being mentioned, please let me know. Thanks again!
Oct 28, 2021, 11:20 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.