👀 Our most exciting product launch yet 🚀 Join us May 8th for Sanity Connect

Issue with filter in deskStructure.js not working as expected, resolved by updating API version.

15 replies
Last updated: Sep 30, 2022
Hi,Can someone please explain why this filter
'_type == "person" && membership.office !=  null
works in a query inside vision but not inside
.filter('_type == "person" && membership.office != null)
in deskStrusture.js?
Sep 30, 2022, 2:13 AM
Hi User. Can you confirm the GROQ versions you’re using in Vision and your desk structure? Is
membership
and/or
office
an array?
Sep 30, 2022, 3:14 AM
Hi User,"@sanity/vision": "^2.34.0",

Not sure where to find deskStructure version

membership is an object that contains

{

name:'office',

title: 'Office',

type: 'string',

initialValue:null,

options:{

list:[

{value:'Commodore', title:'Commodore'},

{value:'Treasurer', title:'Treasurer'},

{value:'Secretary', title:'Secretary'},

{value:'Hire Manager', title:'Hire Manager'}

]

}

},
Sep 30, 2022, 3:14 AM
What do you see in Vision at the top?
Sep 30, 2022, 3:17 AM
Of course, sorry yes thats the version
Sep 30, 2022, 3:18 AM
Perfect, thank you. Can you explain what it means that the filter “works” in one case but not the other?
Sep 30, 2022, 3:19 AM
In vision I get the expected result. ie. an array of 4 members, each of which holds one of the offices.In the studio deskStructure I have the following code
Sep 30, 2022, 3:21 AM
S.listItem()

.title('Officers')

.icon(BsShieldShaded)

.child(

S.documentList()

.title('Officers')

.filter('_type == "person" && membership.office !=  null')

),
but the result is a full list of 'person's..
Sep 30, 2022, 3:22 AM
So you’re getting documents where
membership.office
is null?
Sep 30, 2022, 3:25 AM
correct
Sep 30, 2022, 3:25 AM
Just in case it’s an API version issue: after the filter line, can you add:

.apiVersion('v2022-09-30')

Sep 30, 2022, 3:29 AM
That did it!
Sep 30, 2022, 3:30 AM
So,... Update my api version in Sanity?
Sep 30, 2022, 3:30 AM
Great! Yes, it looks like you may need to specify your API version in your desk structure when you encounter this mismatch.
Sep 30, 2022, 3:39 AM
Cheers for your help,I'm off to have a beer in your honour now
🙂Have a great weekend.
Sep 30, 2022, 3:40 AM
You too!
Sep 30, 2022, 3:41 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?