Skip to main content
info@drupalodyssey.com
Friday, December 4, 2026
Contact

Main navigation

  • Home
  • Services
  • Insights
  • Notebook
  • About
Development

JSON:API vs. GraphQL in Modern Drupal: Selecting the Right Decoupled Architecture for AI & Microservices

December 04, 2026

Every decoupled Drupal project eventually gets to this question: JSON:API or GraphQL? I've heard it in discovery calls, in architecture reviews, and in Slack channels where someone insists GraphQL is the obvious choice because that's what they used before.

The honest answer isn't "it depends." Each solves a different problem. Know your problem, and the choice becomes clear—especially now that Drupal backends are feeding AI agent pipelines, where the difference isn't just ergonomics. It's token budgets, error contracts, and whether your CDN can even cache the responses.

Bottom Line for Stakeholders

Use case Recommended approach
AI agent write-back (automated drafts) JSON:API — deterministic HTTP 422 + source.pointer error contracts
Read-heavy LLM context injection GraphQL — surgical field selection, minimal token footprint
CDN-cached public content delivery JSON:API — plain GET + cache tags (edge purge via the Purge module)
Stable external API contract GraphQL v4/v5 — schema-first, decouples consumers from Drupal internals
New project, general decoupled JSON:API — zero setup, core security coverage, good defaults

The Architectural Divide

JSON:API is part of Drupal core. Enable the module and you have a fully spec-compliant, zero-configuration REST API for every entity type and bundle on your site. [1] No schema files. No resolver plugins.

GraphQL v4 and v5 take the opposite stance. The schema is empty until you define it—Schema Definition Language (.graphqls) files bound to Drupal data via DataProducer plugins. [2] The external API contract is completely decoupled from Drupal's internals; consumers never need to know they're talking to Drupal at all.

One important distinction: GraphQL 3.x, which auto-generated schemas from Drupal entities, is in maintenance mode. Don't build on it. [2] For teams wanting automated schema generation on v4/v5 without hand-rolling SDL, drupal/graphql_compose is a separate contributed module that handles this—not part of the GraphQL module itself. [3]

Feeding AI Agents: Token Economy and Tool Calling

For LLM workflows—RAG pipelines, context injection, prompt grounding—payload size directly impacts model latency and token billing.

An unpruned JSON:API response wraps every resource in spec-mandated envelopes: data, type, id, links, relationships. [4] Sparse fieldsets (fields[node--article]=title,body) prune attribute bloat but can't eliminate the envelope. GraphQL returns exactly what you asked for—nothing else. For read-heavy context assembly, that matters.

The content model underneath shapes how lean either payload can get. Content architectures AI models understand covers that layer directly.

Where the calculus flips is tool-calling. Autonomous AI agents using OpenAI Function Calling, Anthropic Tool Use, or MCP need narrow, precise tool schemas. JSON:API's per-bundle endpoints—/jsonapi/node/article, /jsonapi/taxonomy_term/tags—map cleanly to modular REST tool definitions each small enough to fit in a system prompt. [1] GraphQL gives an agent one endpoint and a schema to explore. A hand-built v4/v5 schema can stay small, but generate it from your whole entity model with GraphQL Compose and introspection gets large fast. Feed that into an LLM context window and you've spent your token budget before the agent runs a single query.

That token-budget problem is part of a larger context assembly question. Architecting AI context in Drupal covers how to structure it.

Query Batching and Relationship Traversal

GraphQL's internal EntityBuffer collects entity IDs across all fields in a query and resolves them in a single loadMultiple() call. [5] One HTTP request retrieves an article, its author profile, its taxonomy terms, and site configuration simultaneously.

JSON:API needs help here. The drupal/subrequests module handles single-bootstrap batch execution via POST blueprints with JSONPath token substitution. [6] It works, but adds client-side complexity that GraphQL's native query syntax eliminates. For AI agents traversing complex entity graphs, GraphQL's batching model is cleaner.

Writing Back: Automated Draft Ingestion

This is where JSON:API's design discipline pays off most clearly for AI pipelines.

When an LLM agent submits a draft via JSON:API POST, Drupal's entity validation runs automatically. If validation fails, EntityResource returns HTTP 422 Unprocessable Entity with JSON:API error objects, each with an exact source.pointer (/data/attributes/title). [7] An agent can parse these deterministically and self-correct on the next attempt. I run this pattern on this site. The content pipeline that produced this post ends with an AI agent creating the draft through JSON:API, then reading the stored node back and patching anything that didn't come through as intended, before I ever review it.

GraphQL mutations require building that error contract from scratch—custom input types, mutation resolvers, manual violation mapping. [2] When validation fails, GraphQL returns HTTP 200 with a top-level errors array, which breaks HTTP-status-based retry logic and circuit breakers. For write-back AI pipelines, JSON:API wins clearly.

Caching: Where GraphQL Has Real Work to Do

JSON:API responses carry Drupal cache tags (node:1, node_list, taxonomy_term:5) as cacheability metadata. [8] Dynamic Page Cache uses them out of the box. For Varnish, Fastly, or Cloudflare, add the Purge module and your CDN's purger. Entity saves then call Cache::invalidateTags() and the edge drops exactly the responses that changed.

Most GraphQL clients send queries as HTTP POST, and CDNs and reverse proxies don't cache POST. The module accepts GET too, but long query strings make poor cache keys.

The practical route to edge caching is Persisted Queries: pre-registered by hash, fetched via HTTP GET, with correct cache tag bubbling on the response. [5] It works—but it requires a client build step synchronizing query hashes with the backend. JSON:API's GET requests need no client-side build step.

Schema Governance Over Time

JSON:API has zero maintenance overhead. Add fields in Drupal's Field UI; they appear in the API automatically. [1] The tradeoff: your internal entity naming leaks into the external contract unless you use jsonapi_extras.

GraphQL v4/v5 requires coordinated deployments. Every new field needs an SDL update and a registered resolver. [2] The external contract stays clean, but someone owns it. drupal/graphql_compose automates entity mapping significantly, though it adds another contributed dependency. [3] If your content model evolves frequently, that governance overhead adds up fast.

JSON:API vs. GraphQL: Architectural Decision Matrix

Dimension JSON:API GraphQL v4/v5
Schema paradigm Zero-config, entity-bound Schema-first, contract-driven
Setup complexity None (core module) SDL + resolvers (or Compose)
LLM token efficiency Good with sparse fieldsets Better: surgical selection
LLM tool definitions Excellent: narrow per-bundle endpoints Risk of schema bloat
Edge caching Native GET + cache tags (CDN purge via Purge module) Requires Persisted Queries
AI write-back errors HTTP 422 + source.pointer (deterministic) HTTP 200 + manual violation mapping
Multi-entity batching Subrequests module required Native (EntityBuffer)
Schema maintenance Zero Ongoing (mitigated by Compose)

When I'd Pick Each

JSON:API when: AI agents need reliable write-back with deterministic error handling; you need CDN edge caching with zero configuration; your team lacks GraphQL schema expertise; or you're in early stages and velocity matters.

GraphQL v4/v5 when: you need a stable external API contract decoupled from Drupal's internals; read-heavy LLM pipelines demand maximum payload efficiency; or you have a team willing to own schema governance long-term.

Here's my actual approach with clients: JSON:API as the default, GraphQL added when a specific use case earns it—typically a consumer-facing query layer where token economy genuinely matters. Running both isn't contradictory. They're different tools.

Start with JSON:API. Add GraphQL when you have a reason, not because someone read a blog post about it.

If you're designing a Drupal backend for AI agent workflows or microservice integration and want a second set of eyes on the architecture before you commit, let's talk.

Get Your Architecture Review

Sources

[1] https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module - JSON:API module
[2] https://www.drupal.org/project/graphql - GraphQL module
[3] https://www.drupal.org/project/graphql_compose - GraphQL Compose
[4] https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module… - JSON:API core concepts
[5] https://drupal-graphql.gitbook.io/graphql/ - GraphQL module documentation
[6] https://www.drupal.org/project/subrequests - Subrequests module
[7] https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/jsonapi/src/… - Core EntityResource.php
[8] https://www.drupal.org/docs/drupal-apis/cache-api/cache-tags - Drupal cache API (cache tags)
Author

Ron Ferguson

 

Next Blog

Ad - Header (728*90 AD)

Ad - Sidebar (300 x 600 AD)

Ad - Sidebar (300 x 250 AD)

Newsletter

Subscribe my Newsletter for new blog and tips.

Menu

  • Home
  • Services
  • Insights
  • Notebook
  • Portfolio
  • Resources
  • About

Legal

  • Privacy Policy
  • Terms & Conditions
  • Disclaimer

I specialize in custom development, performance tuning, and reliable maintenance, delivering clean code and strategic solutions that scale with your business. Ready to discuss your project?

E: info@drupalodyssey.com
Fort Worth, TX

© 2026 All Rights Reserved.

Drupal is a registered trademark of Dries Buytaert. Drupal Odyssey is an independent consultancy
and is not affiliated with or endorsed by the Drupal Association or the Drupal project.

Proud supporter of active military, veterans and first responders.