Sanity Pioneers: Get early access to betas, extra AI credits, and a direct line to the engineering team. Apply now

Nested array of references in GROQ query for exhibitions with artworks and artists

29 repliesLast updated: Nov 30, 2025

Morning everyone. I have a question regarding a nested array of references.My GROQ request is like this (see below).

const exhibitionFields = groq`
  _id,
  name,
  dateStart,
  dateEnd,
  "artworks": artworks[]->{..., "artists":artists[]->{name},"image":image.asset->url},
  "curators": curators[]->{name},
  pressRelease,
  description,
  excerpt,
  "slug": slug.current,
`
AI Update

Based on your GROQ query, it looks like you're working with nested arrays of references - specifically dereferencing artworks and then dereferencing artists within each artwork. Your syntax looks correct! Let me explain what's happening and address any potential considerations.

Your query structure:

"artworks": artworks[]->{..., "artists":artists[]->{name},"image":image.asset->url}

This is doing several things:

This nested dereferencing pattern is perfectly valid in GROQ. The reference access operator (->) works with arrays and can be nested as you're doing.

A few things to keep in mind:

Performance: Each -> operator performs an internal subquery, so deeply nested references can impact query performance. With artworks[]-> and then artists[]-> inside, you're potentially making many subqueries if you have lots of artworks with multiple artists each.

Syntax variation: You could also write the artists dereferencing in a slightly different way:

"artists": artists[]->{name}
// or if you want just the names as a flat array:
"artists": artists[]->name

The second form (artists[]->name) gives you a flat array of names directly, while your current syntax (artists[]->{name}) gives you an array of objects each with a name property.

Common issues to check:

Your GROQ syntax looks correct, so if you're experiencing specific issues, they're likely related to the data structure or schema configuration rather than the query syntax itself. What specific problem are you running into?

Show original thread
29 replies

Was this answer helpful?

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Related contributions