Skip to content

Sanity GROQ vs GraphQL: which query language to use

Compare GROQ and GraphQL in Sanity: zero-deploy schema changes, inline joins, Sanity TypeGen with defineQuery, and when GraphQL still makes sense.

Updated 3 December 2026Tested with
  • sanity 6.24.0
  • next-sanity 13.5.1

Sanity supports both GROQ (its native query language) and GraphQL. For almost every Next.js or Astro site, pick GROQ: it requires zero deploy step when your schema changes, supports arbitrary projections and joins in one request, and works out of the box with next-sanity and TypeGen.

GROQ vs GraphQL in Sanity

AspectGROQGraphQL
Schema deploy stepNone — queries work immediatelyMust run sanity graphql deploy after every schema change
Joins & referencesInline with -> (author->{name, image})Typed nested fields
Filtering & slicingRich expressions, counts, coalescing (coalesce())Limited to generated filter types
TypeScript typessanity typegen generate infers exact query result typesGraphQL Code Generator
Best fit95% of websites, Next.js, Astro, blogs, SaaSTeams already running a federated GraphQL gateway (Apollo/Mesh)

What a real GROQ query looks like

src/sanity/queries.tsTypeScript
import { defineQuery } from "next-sanity"; export const POSTS_QUERY = defineQuery(`  *[_type == "post" && defined(slug.current)] | order(publishedAt desc) [0...12] {    _id,    title,    "slug": slug.current,    publishedAt,    "author": author->{ name, role }  }`);

Wrapping the query in defineQuery lets npx sanity typegen generate produce the exact TypeScript return type automatically — giving you the main benefit people historically picked GraphQL for, without maintaining a separate GraphQL schema deployment.

When GraphQL still makes sense

  • Your company already stitches multiple backends behind an Apollo or WunderGraph gateway and wants Sanity exposed as one more subgraph.
  • Multiple non-JS clients (iOS, Android) already share a strict GraphQL schema contract.

Questions

Is GROQ cheaper than GraphQL on Sanity's API quota?

Both count as API requests against the same quota, but GROQ often uses fewer requests because you can fetch unrelated document types (e.g. site settings + navigation + page content) in a single object projection. Estimate your monthly bill with our Sanity pricing calculator.

Where can I find starter Sanity schemas?

Copy or install our free Sanity content models for posts, authors, FAQs, events and jobs.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.