Trouble constructing a groq query to expand a nested reference to a 'work' document.

4 replies
Last updated: Mar 17, 2023
I'm having trouble constructing a groq query to expand a nested reference to a 'work' document. I have and array of flexible objects on the 'home' document named 'pageSections', one of which is a 'workGallery' that includes an array of 'works' each of which reference a 'work' document.

*[_type== "home"] {

pageSections[] {



works[] {






I have another section named singleTestimonial that references a 'testimonial' document which I can expand. But it doesn't work with the 'work' one. I'm at a bit of a loss.
Mar 16, 2023, 1:54 AM
This is what I get if I just query the pageSections in the vision playground:
[…] 1 item
0:{…} 1 property
pageSections:[…] 3 items
0:{…} 6 properties
color:{…} 2 properties
works:[…] 2 items
0:{…} 3 properties
1:{…} 3 properties
1:{…} 8 properties
color:{…} 2 properties
introTitle:We design websites, publications and brands.We develop for mobile, tablet and desktop devices.
listOne:[…] 3 items
listTwo:[…] 3 items
2:{…} 4 properties
color:{…} 2 properties
testimonial:{…} 10 properties
:2023-03-09T19:12:50ZshortQuote:“They were especially good at bringing our organisation and our customers experiences together...and translating that into a website that delivers a great experience. ”
Mar 16, 2023, 2:15 AM
It looks like the
array holds just the reference? if that’s the case, this may work,

*[_type== "home"] {
  pageSections[] {
Mar 16, 2023, 12:02 PM
user J
you legend! That worked perfectly. I think I had in my head I was expanding the reference within rather than the whole array. Thanks so much for the help!
Mar 17, 2023, 1:26 AM
user P
no problem! glad it worked for you 🙂
Mar 17, 2023, 1:29 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?