Query Returning Expected Results in Vision but not in Custom Validation
Last updated: Apr 30, 2021
I cannot seem to find the documentation for the recent API changes (2021-03-25). I have a query that will return the expected results in Vision with this version, but using that same query in a custom validation yields no results. It appears that Studio is using the v.1 API internally (for the client it exposes through the parts system). Can anyone confirm this?
Apr 29, 2021, 4:01 PM
This is the query:
• on v.1: count: 0
And these are the params:
count(*[_type == 'product' && ( $value in variants[(_key != $key && ^._id in [$draft, $published])].id ) ])
• on v2021-03-25: count: 1 (expected)
• on v.1: count: 0
Apr 29, 2021, 4:06 PM
While the query can be rewritten as:
It still strikes me as odd that the client that is exposed remains on the v.1 API.
count(*[_type == 'product' && ( _id in [$draft, $published] && $value in variants[_key != $key].id ) ])
Apr 29, 2021, 4:17 PM
user Ycould you please clarify the difference between the following pieces of GROQ? They yield different results, the first one works as expected during validation, while the other doesn't:
!(_id in [$published]) && $value in variants.id
$value in variants[!(^._id in [$published])].id
Apr 29, 2021, 5:01 PM
The changes for the recent api change can be found here: https://www.sanity.io/changelog?platforms=Content+Lake&platforms=GROQ#a6473a5c1682
Apr 30, 2021, 1:25 PM
Thanks, that explains the
^related differences I was seeing! I couldn't find the changelog linked in the documentation though, where did you find it?
Apr 30, 2021, 1:27 PM
I ended up searching the help-channel, but did the exact same thing as you yesterday: posting here in search of a consolidated list😛 https://sanity-io-land.slack.com/archives/C9Z7RC3V1/p1619702012228200
Apr 30, 2021, 1:28 PM
Cool, thanks! I just re-checked the site search and it actually doesn't show up there either!
Apr 30, 2021, 1:29 PM
It would, as you note, be helpful to either link to the changelog in the document on api-versioning, or make the changelog searchable 🙂
Apr 30, 2021, 1:30 PM
My hunch that internally, the
v.1API is being used appears to be correct: https://github.com/sanity-io/sanity/commit/194b40c99862efb5a9a597c36980ff365df6e085
Apr 30, 2021, 5:48 PM
Which is good to know when prototyping queries in
Visionwith a different API version 😆
Apr 30, 2021, 5:49 PM
Sanity.io – build remarkable experiences at scale
Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.