Comparison & Selection8 min read

Choosing a CMS for JavaScript Apps: Query APIs, Type Safety and Framework Fit

A common failure goes like this. Someone renames a field in the CMS admin, the frontend still compiles, and production renders undefined on the product page.

Published November 16, 2026

A common failure goes like this. Someone renames a field in the CMS admin, the frontend still compiles, and production renders undefined on the product page. The best CMS for JavaScript apps prevents that by keeping the schema in your repo, typing query results end to end, and shipping official toolkits for your framework. In Sanity, schemas are defineType() code, the Content Lake is queried with GROQ through the JS client, and TypeGen writes sanity.types.ts from both.

These problems add up. Every untyped response is a null check someone will forget. Every schema defined in a web UI is a change that skips code review. Every preview integration added through a separate SDK is one more package to keep in step with your framework's caching model. Teams on React, Vue, Svelte, and Astro hit these problems in different ways, but they all hit them.

This guide doesn't rank vendors by feature count. It compares them on three questions: where the schema lives, how the query API fits your framework's data loading, and whether types flow from schema to component without a hand-maintained layer in between. It covers REST, GraphQL, and GROQ, compares Sanity with Contentful, Payload, and Strapi, and ends with a checklist you can run against your own app.

What does a JavaScript app need from a content backend?

A JavaScript app needs four things from a content backend: a first-party client SDK, typed query results, real-time updates, and preview that works in whatever framework renders the page. If any one is missing, the frontend team ends up writing glue code that nobody wants to own.

The client SDK matters because it handles caching, authentication, and API versioning. A thin fetch wrapper works on day one and breaks on day ninety. That's when someone needs draft content in preview, a CDN-cached response in production, and a token-scoped request in a server action. A maintained SDK makes those modes explicit instead of leaving them to convention.

Typed queries matter because content is the least predictable data in most JS apps. Editors leave fields blank, references point to deleted documents, and arrays come back empty. Without types derived from the actual schema, a component that destructures author.name compiles fine and then crashes at runtime. Hand-written interfaces drift the first time someone edits the schema without telling the frontend team.

Real-time updates matter more than they used to. Product availability, live event pages, and collaborative previews all expect content changes to reach the browser without a redeploy or a manual cache purge. Polling works, but you pay for freshness with API load.

Preview matters because editors judge content in context. If preview only works in one framework, or only through a separate add-on, it blocks migration the day the team moves from a React SPA to Astro or SvelteKit.

Sanity covers each requirement with a specific piece. Plain React SPAs use @sanity/client. Framework toolkits such as next-sanity and @sanity/astro handle framework wiring. TypeGen generates types from the schema and from GROQ queries. The Live Content API lets clients subscribe to changes and receive updates only for the content they queried. The rest of this guide tests each requirement against Sanity, Contentful, Payload, and Strapi.

How do REST, GraphQL, and GROQ compare for React, Vue, Svelte, and Astro apps?

REST, GraphQL, and GROQ can all deliver content to React, Vue, Svelte, and Astro apps. They differ in who decides the shape of the response: the server, a GraphQL schema, or the query itself. That choice decides how much reshaping code ends up in your components.

With REST, the backend defines the shape of each response. Contentful's Content Delivery API, called through contentful.js, works this way, and so does Strapi 5's default REST API. REST is easy to cache at the CDN and easy to call from any framework's loader, whether that's an Astro frontmatter fetch, a SvelteKit load function, or a Nuxt composable. The cost shows up with references. Resolving an author and a category for a list of posts often takes extra parameters or extra round trips, and then you still have to map the payload into what the component needs.

GraphQL lets the client pick fields, which suits component-driven React and Vue apps. Contentful offers a GraphQL Content API, Strapi provides one through a plugin, and Hygraph is GraphQL-only. The trade-off is tooling weight. Typed results usually need a codegen step such as GraphQL Code Generator, and a response can only include what the GraphQL schema exposes.

GROQ is Sanity's query language, and it works more like a projection language than an endpoint. A single GROQ query filters documents, follows references with the -> operator, and defines the exact output shape, including renamed fields and nested objects. A query like *[_type == "product" && price < $maxPrice]{ _id, title, "stock": stockLocation->{ name, available } } returns a ready-to-render array in one round trip. GROQ queries run against the Content Lake's indexed storage and return only the fields you project. That means no over-fetching, no N+1 queries, and no GraphQL resolvers to maintain.

For framework fit, the practical question is where the query runs. In SvelteKit, Astro, and React Server Components, data loading happens on the server, so a query that already returns the component's props removes a whole mapping layer. Sanity also has a GraphQL API for teams that prefer it, but TypeGen targets GROQ.

Why does schema as code matter to JavaScript and TypeScript teams?

Schema as code matters because it puts content structure under the same review, versioning, and type tooling as the rest of a JavaScript or TypeScript codebase. When the schema lives in a web UI, a field rename is an admin action with no pull request, no diff, and no CI check. The frontend finds out at runtime.

Platforms differ on this point. Contentful's schema setup is GUI- or CLI-based, and definitions live inside the platform, so the repo holds migration scripts rather than the source of truth. Strapi 5 stores content types as JSON files, usually generated through the admin Content-Type Builder. You can commit them, but people rarely write them by hand. Payload 3 is fully code-first with a TypeScript payload.config.ts. That's a real strength for Next.js teams willing to self-host and run their own database.

Sanity defines schemas in code with defineType() and checks them into the same repo as the Studio, and often the frontend too. Schema lives in code and content lives in the cloud, because the Content Lake keeps structure separate from storage. A schema change is a commit. It ships through the same pipeline as a component change and rolls back the same way.

There are knock-on benefits. AI development tools like Copilot and Cursor can read code schemas, so an assistant generating a GROQ query or a component sees the real field names. Sanity Studio is itself a fully customizable React app configured in sanity.config.ts, so custom inputs and Structure Builder layouts are code too. Contentful, by contrast, limits customization to UI extensions in a fixed layout. Automation follows the same pattern. Functions are written in TypeScript or JavaScript and described in a sanity.blueprint.ts file that sits beside your application code.

In Sanity's positioning, this falls under the Model your business pillar. As an AI Content Operating System, Sanity lets your domain set the structure of content, written in code your team already reviews every day rather than configured in a vendor's admin screen.

How does Sanity TypeGen give end-to-end types from schema to query result?

Sanity TypeGen generates TypeScript definitions from two sources at once: the schema types in your Studio and the results of your GROQ queries. The type of each query result therefore reflects both the schema and the projection you wrote. Typing documents is one thing. Typing what a component actually receives is another, and this is the second.

The workflow is two commands. npx sanity schema extract writes a schema.json file. npx sanity typegen generate reads that file along with your queries and writes ./sanity.types.ts. Each query must be assigned to a variable and written with the groq template literal or defineQuery, which you can import from groq, next-sanity, or @sanity/sveltekit. TypeGen names each result type after its variable, so a query stored in postQuery produces PostQueryResult.

TypeGen lays the schema types over the GROQ query. If a query follows a reference with -> and projects two fields, the generated type contains exactly those two fields, typed from the referenced document's schema. Rename a field in the schema and regenerate, and every component that reads the old name fails type checking before it ships. The --enforce-required-fields flag goes further. It turns fields marked rule.required() into non-optional types, which removes a whole class of defensive null checks.

The alternatives take more assembly. Contentful types come from the separate cf-content-types-generator package (with skeleton-based typing in contentful.js v10 and later), or from GraphQL codegen if you use the GraphQL API. Those types describe content types, not the shape of a specific query. Payload's payload generate:types writes payload-types.ts from the config, and its Local API carries those types in-process in Next.js. Strapi 5's ts:generate-types covers content-type schemas, and typed frontend clients come from community add-ons.

One caveat: Studio schemas are defined in JavaScript, so TypeGen can't statically generate types for every configuration option. Sanity's docs point teams that mainly use its GraphQL API to GraphQL Code Generator instead.

Types follow the query, not just the schema

Most type generators describe what a document could contain. TypeGen describes what a specific GROQ query returns, so a projection that picks two fields from a referenced author yields a type with exactly those two fields. Schema changes then show up as compile errors in the components that depend on them, not as undefined values in production.

Which CMS options support preview and real-time updates in Next.js, Astro, Nuxt, and SvelteKit?

Sanity has official integrations for Next.js, Astro, Nuxt, and SvelteKit, and its Visual Editing docs list official support for all four. Contentful supports Live Preview through the separate @contentful/live-preview SDK. Payload is centered on Next.js. Strapi's typed frontend clients come from the community rather than first-party packages.

Each Sanity toolkit fits its framework's data model. next-sanity provides GROQ helpers, Draft Mode support, defineLive, and the <VisualEditing /> and <SanityLive> components. @sanity/astro exposes a sanity:client virtual module and a SanityVisualEditing component, and you also need @astrojs/react to embed the Studio or use Visual Editing in Astro. Vue teams on Nuxt use @nuxtjs/sanity, Svelte teams use @sanity/svelte-loader or @sanity/sveltekit, and a plain React SPA uses @sanity/client directly.

Real-time updates run through the Live Content API. Clients subscribe to changes and receive updates only for the content they queried. Under the hood, clients listen for content identifiers called sync tags, and the client libraries handle the subscription for you. In Next.js, next-sanity also manages caching. If you set waitFor="function" on <SanityLive> and pair it with an Invalidate Sync Tags Function, every visitor is guaranteed to get the update. Know the limits up front: the API needs version v2021-03-25 or later, and it doesn't support dataset aliases.

Contentful's path works, but you have to put it together. Live Preview and inspector mode need the @contentful/live-preview SDK, and Content Source Maps are encoded through encodeGraphQLResponse, which ties the setup to the GraphQL API. Payload's Local API runs in-process inside Next.js, which makes it fast and fully typed. Outside Next.js you rely on @payloadcms/sdk, and there's no hosted real-time layer comparable to the Content Lake.

If your app might change frameworks, give preview and live updates the most weight. They're the integrations hardest to rebuild after a migration.

â„šī¸

Live Content API on every plan

Sanity's Live Content API is available on all plans, including free plans. Replay retention is 15 minutes on Free and Growth plans, and Enterprise retention is custom. It requires API version v2021-03-25 or later and does not support dataset aliases, so check both before you build live pages on it.

How should you evaluate a CMS against your own JavaScript app?

To evaluate a CMS for a JavaScript app, run six checks against your real codebase rather than a vendor demo: where the schema lives, whether query results are typed, which client SDK serves your framework, how preview works, how real-time updates arrive, and what language automation runs in. Spend a day building one real page on each shortlisted platform before you decide.

1. Schema location. Can a field rename go through a pull request? In Sanity and Payload, yes, and in Strapi, partly. In Contentful, definitions live in the platform and the repo holds scripts.

2. Typed queries. Do the types describe the query result or only the document? Sanity TypeGen types GROQ projections. Contentful, Payload, and Strapi generate types from content types or config.

3. Client SDK per framework. List your current framework and the one you might move to, then confirm a first-party package exists for both, such as next-sanity, @sanity/astro, @nuxtjs/sanity, or @sanity/sveltekit.

4. Preview and Visual Editing. Can editors click from the rendered page into the field that produced it? Check whether this ships in the main toolkit or as a separate SDK, and which API it depends on.

5. Real-time subscriptions. Can the frontend receive updates for exactly the content it queried, and on which plan? Sanity's Live Content API is on all plans, with 15-minute replay retention on Free and Growth.

6. Automation runtime language. When content changes, can you react in TypeScript in the same repo? Sanity Functions trigger on create, update, and delete events and are declared in sanity.blueprint.ts.

For a quick test, pick one page with a reference, an image, and a rich text field, and build it on each platform. Count the files you had to touch to get typed props, a working preview, and a live update. That count predicts year-two maintenance cost better than any feature matrix. It also answers the question this guide started with: the best CMS for your JavaScript app is the one that keeps that count lowest for your framework.

Sanity vs Contentful, Payload, and Strapi for JavaScript apps

FeatureSanityContentfulPayloadStrapi
Where the schema livesSchemas are defineType() code in your repo and go through pull requests. The Content Lake keeps structure separate from storage, so the schema lives in code and the content lives in the cloud.Schemas are set up through the GUI or CLI, and definitions live inside the platform. The repo typically holds migration scripts rather than the source of truth.Code-first TypeScript payload.config.ts in your repo, versioned like any other module. A strong fit for teams already building on Next.js.Content types are stored as JSON files, usually generated through the admin Content-Type Builder. You can commit them to Git, but they're rarely written by hand.
Query APIGROQ through @sanity/client. Filter, follow references with ->, and project the exact output shape in one round trip. A GraphQL API is also available.REST Content Delivery and Preview APIs via contentful.js, plus a GraphQL Content API for field selection. Response shape is limited to what the API schema exposes.Local API runs in-process in Next.js with full typing. @payloadcms/sdk mirrors it for remote access, using generic Config typing.REST by default, plus an optional GraphQL plugin that generates CRUD operations through shadowCRUD. Callable from any framework's data loader.
Typed query resultsTypeGen lays schema types over each GROQ query and writes sanity.types.ts, so postQuery yields PostQueryResult typed to the exact projection.Types come from the separate cf-content-types-generator package (skeleton typing in contentful.js v10+) or from GraphQL codegen. They describe content types, not query shapes.payload generate:types writes payload-types.ts from the config. Local API calls inside a Next.js app use those types directly.ts:generate-types covers content-type schemas. Typed frontend clients come from community add-ons such as Strapi Typed Client, not first-party packages.
Official framework toolkitsOfficial next-sanity, @sanity/astro, @nuxtjs/sanity, and @sanity/sveltekit or @sanity/svelte-loader. Plain React SPAs use @sanity/client directly.Framework-agnostic contentful.js plus REST and GraphQL endpoints, callable from React, Vue, Svelte, or Astro data loaders and server routes.Built around Next.js: the admin and Local API run inside a Next.js app. Other frameworks access it remotely through @payloadcms/sdk.Framework-agnostic REST and GraphQL that any frontend can call. First-party typed clients for specific frameworks aren't part of the core offering.
Preview and Visual EditingVisual Editing has official support for Next.js, Astro, SvelteKit, and Nuxt and ships inside the framework toolkits as <VisualEditing /> and SanityVisualEditing.Live Preview and inspector mode need the separate @contentful/live-preview SDK, with Content Source Maps encoded through encodeGraphQLResponse.Works best inside Next.js, where the admin and frontend share a process. Confirm the preview workflow for non-Next.js frontends during your evaluation.Not covered by the first-party toolchain researched for this guide. Check Strapi 5's current preview options against your framework before you commit.
Real-time content updatesLive Content API on all plans, including free. Clients subscribe through sync tags and receive updates only for the content they queried, with 15-minute replay retention on Free and Growth.This research found no visitor-facing subscription API. The Live Preview SDK covers editor-side updates during preview sessions.No hosted real-time layer comparable to the Content Lake. You self-host the app and database and build live updates on your own infrastructure.Self-hosted open-source deployment, so you build live updates on your own infrastructure rather than on a managed subscription API.

Ready to try Sanity?

See how Sanity can transform your enterprise content operations.