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

29 replies
Last 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:

  1. artworks[]-> - dereferencing each item in the artworks array
  2. Inside each artwork, "artists":artists[]-> - dereferencing each artist reference within that artwork
  3. "image":image.asset->url - dereferencing the image asset

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:

  • Make sure your references are properly defined in your schema with type: 'reference'
  • Verify that the referenced documents actually exist in your dataset
  • Check that _key properties exist on array items if you're updating them (required for objects in arrays)

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

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.

Was this answer helpful?