Graphql vs Openapi
GraphQL is a query language and runtime that lets clients ask for exactly the data they want. OpenAPI is a specification standard for describing REST APIs. They solve overlapping problems from opposite ends, and most teams pick wrong because they confuse "modern" with "appropriate."
The short answer
Openapi over Graphql for most cases. For the overwhelming majority of teams, an OpenAPI-described REST API ships faster, caches for free, and survives staff turnover.
- Pick Graphql if have many heterogeneous clients (mobile, web, partners) each needing different slices of a deeply nested graph, and over-fetching or N round-trips is a measured, real problem
- Pick Openapi if building a normal HTTP API consumed by services and apps, want HTTP caching, generated SDKs, and tooling that any engineer already understands. This is most teams
- Also consider: They aren't mutually exclusive: many shops expose REST documented by OpenAPI and add a thin GraphQL gateway only where the data-shape mismatch actually hurts. Don't adopt GraphQL for résumé reasons.
— Nice Pick, opinionated tool recommendations
They aren't even the same kind of thing
This is half the confusion right here. GraphQL is a runtime: a type system, a query language, and an execution engine that resolves fields. OpenAPI is paperwork — a YAML/JSON contract that describes endpoints you already built with plain HTTP. Comparing them is comparing an engine to a blueprint. The honest framing: GraphQL replaces how you query, while OpenAPI just documents REST you wrote anyway. So the real question is 'GraphQL vs REST,' with OpenAPI standing in as 'REST done with a real contract.' People reach for GraphQL because REST felt undocumented and ad hoc — but that pain is usually a missing OpenAPI spec, not a missing query language. Fix the documentation gap before you swap your entire data layer. Most GraphQL migrations are expensive solutions to a problem a schema file would have solved for free.
Caching: GraphQL's self-inflicted wound
REST gets HTTP caching for free. A GET request has a URL, and every CDN, browser, and reverse proxy on earth knows how to cache a URL. OpenAPI describes those GETs cleanly, and Varnish or Cloudflare does the rest while you sleep. GraphQL throws this away. Everything is a POST to /graphql with the query in the body, so your edge cache is blind — it can't tell two requests apart without parsing GraphQL it doesn't understand. You end up bolting on persisted queries, Apollo's normalized client cache, or APQ hashing to claw back what REST handed you on day one. That's real engineering effort spent rebuilding a wheel you removed. If your workload is read-heavy and cacheable — which most public APIs are — GraphQL starts in a hole and asks you to dig out. OpenAPI-described REST never falls in.
Tooling and the new-hire test
Apply the new-hire test: a backend engineer you hired yesterday can read an OpenAPI spec and hit your endpoints with curl before lunch. The mental model is HTTP, which they've known their whole career. OpenAPI's ecosystem is enormous and boring in the best way — Swagger UI, generated typed clients in twenty languages, Postman import, contract testing, mock servers, all mature. GraphQL's tooling is genuinely excellent too (GraphiQL, codegen, federation), but it demands real onboarding: resolvers, the N+1 problem, dataloaders, schema stitching, and a query-cost analysis you must build yourself or get DoS'd by a five-line nested query. GraphQL's power is also its footgun — clients can ask for anything, including 'everything, recursively.' OpenAPI's rigidity is a feature here: the surface is finite, so it's defensible and predictable. Boring scales across a team. Clever concentrates knowledge in the one person who'll quit.
When GraphQL actually earns it
Credit where due: GraphQL is the right pick when the data-shape mismatch is real and measured, not imagined. If you have a mobile app over a flaky network making six sequential REST calls to assemble one screen, GraphQL's single round-trip with exactly-the-needed-fields is a genuine win — that's the problem it was born at Facebook to solve. Same for a sprawling graph (users → posts → comments → authors) where every client wants a different slice and REST forces either over-fetching or an explosion of bespoke endpoints. Federation across many backend teams is another legitimate case. The test is simple: can you name the specific pain? 'Over-fetching costs us 200ms on the product page' is a reason. 'It's modern' and 'REST feels old' are not — they're how you end up maintaining a resolver layer and a custom caching stack to serve traffic that three documented GET endpoints handled fine.
Quick Comparison
| Factor | Graphql | Openapi |
|---|---|---|
| HTTP caching out of the box | Lost — POST /graphql defeats edge/CDN caches; needs persisted queries to recover | Free — every GET is a cacheable URL any CDN understands |
| Eliminating over-fetch / N round-trips | Native — clients request exact fields in one query | Manual — bespoke endpoints or accept over-fetching |
| Onboarding and ubiquity of tooling | Strong tooling but real learning curve (resolvers, N+1, query cost) | Plain HTTP; mature, boring, universally understood |
| Attack surface / abuse control | Clients can craft expensive deep queries; you must add cost limits | Finite, fixed endpoint surface; predictable and defensible |
| It's a spec vs a runtime | A full query runtime you must operate | A contract describing REST you already have |
The Verdict
Use Graphql if: You have many heterogeneous clients (mobile, web, partners) each needing different slices of a deeply nested graph, and over-fetching or N round-trips is a measured, real problem.
Use Openapi if: You're building a normal HTTP API consumed by services and apps, want HTTP caching, generated SDKs, and tooling that any engineer already understands. This is most teams.
Consider: They aren't mutually exclusive: many shops expose REST documented by OpenAPI and add a thin GraphQL gateway only where the data-shape mismatch actually hurts. Don't adopt GraphQL for résumé reasons.
Graphql vs Openapi: FAQ
Is Graphql or Openapi better?
Openapi is the Nice Pick. For the overwhelming majority of teams, an OpenAPI-described REST API ships faster, caches for free, and survives staff turnover. GraphQL is a precision tool for client-data-mismatch problems, not a default. Pick OpenAPI unless you can name the specific GraphQL pain it solves.
When should you use Graphql?
You have many heterogeneous clients (mobile, web, partners) each needing different slices of a deeply nested graph, and over-fetching or N round-trips is a measured, real problem.
When should you use Openapi?
You're building a normal HTTP API consumed by services and apps, want HTTP caching, generated SDKs, and tooling that any engineer already understands. This is most teams.
What's the main difference between Graphql and Openapi?
GraphQL is a query language and runtime that lets clients ask for exactly the data they want. OpenAPI is a specification standard for describing REST APIs. They solve overlapping problems from opposite ends, and most teams pick wrong because they confuse "modern" with "appropriate."
How do Graphql and Openapi compare on http caching out of the box?
Graphql: Lost — POST /graphql defeats edge/CDN caches; needs persisted queries to recover. Openapi: Free — every GET is a cacheable URL any CDN understands. Openapi wins here.
Are there alternatives to consider beyond Graphql and Openapi?
They aren't mutually exclusive: many shops expose REST documented by OpenAPI and add a thin GraphQL gateway only where the data-shape mismatch actually hurts. Don't adopt GraphQL for résumé reasons.
For the overwhelming majority of teams, an OpenAPI-described REST API ships faster, caches for free, and survives staff turnover. GraphQL is a precision tool for client-data-mismatch problems, not a default. Pick OpenAPI unless you can name the specific GraphQL pain it solves.
Related Comparisons
Disagree? nice@nicepick.dev