Joint session with Vercel: How to build intelligent storefronts (May 15th)

Querying single image field with asset reference in GROQ

50 repliesLast updated: Nov 29, 2025

Hello everyone! I am not sure why I am having troubles with this, but I have a schema from which I am trying to only query a single field from, it's an image. It looks like this:
const filter = groq`*[_type == "siteSettings"]`;
  const projection = groq`{ image: gigs_image.asset->url}`;
  const query = [filter, projection].join(' ');
  const image = await client.fetch(query).catch(error => console.error(error));
I adapted this query from a different place, where all of the fields of
siteSettings
is used. But here, I only need that one field
gigs_image
. I know I can get that specific field with groq`*[_type == "siteSettings"]{gigs_image}`, but I am not sure how to get the..
.asset->url
stuff there.. I am sorry this is a really poorly phrased question, I am still super new to sanity.
AI Update

No worries, this is a common question when you're getting started with GROQ! The good news is your query is actually really close – you just need to simplify it a bit.

You can absolutely include the .asset->url reference directly in your projection. Here's how to write it:

const query = groq`*[_type == "siteSettings"]{ "image": gigs_image.asset->url }`;
const result = await client.fetch(query).catch(error => console.error(error));

Or if you want the first (and likely only) siteSettings document:

const query = groq`*[_type == "siteSettings"][0]{ "image": gigs_image.asset->url }`;
const result = await client.fetch(query).catch(error => console.error(error));

What's happening here:

The -> operator in GROQ is called the dereference operator, and it follows references to other documents. When you have an image field in Sanity, it stores a reference to an asset document. Using gigs_image.asset->url tells GROQ to:

A few tips:

Hope this helps! GROQ's reference following with -> is super powerful once you get the hang of it.

Show original thread
50 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