Fetching Author Details with a Single GROQ Query in Sanity
Learn how to retrieve a Sanity post and its author in one request using GROQ’s arrow operator, with a worked example, performance tips, and limitations.
14 Sept 2025, 13:57 UTC

Problem: Too many round‑trips for related data
When a blog post references an author document, fetching the post and then the author separately adds latency and wastes bandwidth.
Thesis: A single GROQ query can project the author’s name directly into the post payload
How GROQ joins work
In Sanity, a reference field stores the _id of another document. Using the arrow operator (->) you can follow that reference and select any field from the target document.
Worked example: fetching a post with its author
- Assume a
postschema with fieldstitle,slug, andauthor(typereferencetoauthor). - Assume an
authorschema withnameandpicture. - The GROQ query below returns only the fields needed for a preview card:
*[_type == "post" && slug.current == $slug]{
title,
author->{
name,
picture
}
}
Run it in the Vision tool (Studio → Vision) or via the CLI:
sanity documents query '*[_type == "post" && slug.current == $slug]{title,author->{name,picture}}' --slug hello-world
Check the Network tab: the request URL contains query=... and the response JSON includes only title and the nested author object with name and picture.
Trade‑off and limitation
- Deep dereferencing (
->->) or projecting large arrays increases the query cost shown in the Sanity dashboard’s API usage view. - GROQ cannot perform aggregations like sum or average across many documents; for analytics you must export data or compute client‑side.
To stay safe, keep the projection shallow and limit array slices (e.g., author->picture[0..1]) and monitor the queryCost metric after each deploy.
Actionable closing
Next time you need related data, try the arrow projection in Vision first. If the returned payload matches exactly what your frontend renders, you’ve eliminated an extra request and can rely on the CDN edge cache for the single query.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.