GROQ vs GraphQL: What are the tradeoffs?
Both GROQ and GraphQL are fully supported by Sanity for querying content from the Content Lake, but each has distinct strengths and limitations. Here's what you should know:
What GROQ offers that GraphQL doesn't:
Real-time subscriptions: GROQ works with Sanity's listening capabilities and real-time features, while GraphQL subscriptions aren't currently supported. If you need live content updates, you'll want to use GROQ with the JavaScript client.
Native query language advantages: Since GROQ is Sanity's native query language, it's designed specifically for querying structured content with powerful projections and transformations. It tends to be more flexible for complex content manipulation and can feel more intuitive for Sanity-specific operations.
No deployment step: GROQ works out of the box without needing to deploy an API schema.
What GraphQL offers that GROQ doesn't:
Schema introspection and autocomplete: GraphQL provides automatic documentation and autocomplete in GraphQL playgrounds, making it easier to explore your content model.
Type generation: With tools like GraphQL Code Generator, you can automatically generate TypeScript types from your GraphQL schemas, giving you strong type safety throughout your application.
Ecosystem familiarity: If your team already uses GraphQL or you're working with frameworks like Gatsby (which uses gatsby-source-sanity with GraphQL), GraphQL provides a familiar interface with existing tooling.
Single request efficiency: GraphQL's ability to request exactly what you need in one query can be more intuitive for developers coming from REST backgrounds.
The good news:
You're not locked into one or the other! You can use both in the same project. For example, some developers use GraphQL with Apollo Client for data fetching while using GROQ for live preview subscriptions. Both query languages access the same Content Lake and support features like Perspectives for draft/published content views.
The choice often comes down to team familiarity and specific requirements. If you need real-time updates, GROQ is currently your only option. If you want strong typing and schema introspection, GraphQL might be preferable.
Show original thread8 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.