Query Returning Expected Results in Vision but not in Custom Validation
10 replies
Last updated: Apr 30, 2021
F
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
F
This is the query:
And these are the params:
β’ on v2021-03-25: count: 1 (expected)
β’ on v.1: count: 0
count(*[_type == 'product' && ( $value in variants[(_key != $key && ^._id in [$draft, $published])].id ) ])
{"draft":"drafts.e1e3a7c8-359a-4cda-9fa3-5fcc12af4d91","published":"e1e3a7c8-359a-4cda-9fa3-5fcc12af4d91","value":"2222","key":"1df34ed3cac2"}
β’ on v.1: count: 0
Apr 29, 2021, 4:06 PM
F
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
F
user Y
could 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
H
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
F
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
H
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
F
Cool, thanks! I just re-checked the site search and it actually doesn't show up there either!
Apr 30, 2021, 1:29 PM
H
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
F
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
F
Which is good to know when prototyping queries in
Visionwith a different API version π
Apr 30, 2021, 5:49 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.