Watch a live product demo 👀 See how Sanity powers richer commerce experiences

Query Returning Expected Results in Vision but not in Custom Validation

10 replies
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:
count(*[_type == 'product' &&
  (
    $value in variants[(_key != $key && ^._id in [$draft, $published])].id
  )
])
And these are the params:

{"draft":"drafts.e1e3a7c8-359a-4cda-9fa3-5fcc12af4d91","published":"e1e3a7c8-359a-4cda-9fa3-5fcc12af4d91","value":"2222","key":"1df34ed3cac2"}
• 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:
count(*[_type == 'product' &&
  (
   _id in [$draft, $published] && $value in variants[_key != $key].id
  )
])
It still strikes me as odd that the client that is exposed remains on the v.1 API.
Apr 29, 2021, 4:17 PM
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
vs.

$value in variants[!(^._id in [$published])].id
Apr 29, 2021, 5:01 PM
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.1
API 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
Vision
with a different API version 😆
Apr 30, 2021, 5:49 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the modern content platform that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing