
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou can absolutely use GraphQL with Sanity and Next.js! There's no fundamental reason not to, but there are some important considerations to be aware of in 2024 (and even back in 2021) that might influence your decision.
The biggest thing to know is that Sanity's GraphQL API is read-only - it doesn't support mutations. This means you can query content with GraphQL, but if you need to create, update, or delete content programmatically, you'll need to use the Sanity JavaScript client for those operations.
Additionally, the GraphQL API doesn't support subscriptions, so for real-time content updates or live preview functionality, you'd need to use Sanity's Listening API or the JavaScript client with GROQ.
While GraphQL is a solid choice if you're already familiar with it, GROQ (Sanity's native query language) offers some advantages:
That said, GraphQL has its own benefits like schema introspection, type safety with code generation tools, and familiarity if your team already uses it elsewhere.
If you want to proceed with GraphQL, here's the basic approach:
Deploy your GraphQL API from your Sanity project:
sanity graphql deploySet up Apollo Client (or your preferred GraphQL client) in your Next.js app to query the endpoint at https://YOUR_PROJECT_ID.api.sanity.io/v2023-08-01/graphql/YOUR_DATASET/default
For draft/preview content, you'll need to pass a token with read permissions and use the appropriate Perspectives parameter in your queries. The GraphQL API does support Perspectives for accessing draft content via the overlayDrafts functionality.
For mutations or real-time updates, you'll still need to install @sanity/client and use it alongside your GraphQL setup
Many developers actually use both - GraphQL with Apollo Client for data fetching in their Next.js app, and the Sanity JavaScript client with GROQ for preview subscriptions or content mutations. This gives you the best of both worlds.
In 2024, the recommendation has shifted somewhat toward GROQ as the primary approach, especially with modern features like the Live Content API for real-time content delivery. But GraphQL is still fully supported and works great if it fits your workflow better - it's been out of beta since February 2020 and is described as "one of the richest API offerings in content management". The main thing is understanding the read-only limitation and planning accordingly for mutations and real-time features.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store