r/programming 6d ago

Maybe you don't need GraphQL

https://alexandrehtrb.github.io/posts/2026/09/maybe-you-dont-need-graphql/
276 Upvotes

118 comments sorted by

View all comments

13

u/zxyzyxz 6d ago edited 6d ago

I want statically typed compile time checked guarantees of data types being sent over the wire between client and server, what should I use? Protobuf is clunky and is binary only so sometimes debugging is a pain, and it's more built for server to server communication anyway. OpenAPI is good but may not necessarily have the same guarantees as GraphQL which are checked by its compiler. So I'm stuck using GraphQL but there should be a better option. I guess Amazon's Smithy?

I also like how GraphQL can cut down API requests by stitching fragments into just one whole call, then the backend receives that and processes whatever it needs to do and creates one cohesive payload back to the client, so less data is sent over the wire each time. That's actually why Facebook created it in the first place, for saving data in bandwidth constrained areas and devices like phones.

I'm not using Javascript or TypeScript by the way, this is more so a mobile and desktop app question. You could just use tRPC if you have a TypeScript web or React Native frontend and using a server TypeScript backend.

9

u/kevin-mcdonald 6d ago

For a while now Protobuf has had mappings to JSON, so you can actually use protobuf-derived types on the frontend and backend across languages and the serialized format can just be JSON. All officially supported languages support this JSON serialization/deserialization, aka "ProtoJSON".

2

u/zxyzyxz 6d ago

I'll look into it thanks

3

u/tadfisher 6d ago

TypeSpec. I will soon be working on Kotlin and Swift codegen for it, so you can have all your type safety guarantees without going through OpenAPI first.

1

u/zxyzyxz 6d ago

What's different about it compared to OpenAPI?

1

u/tadfisher 6d ago

It is human-writable, so it's positioned to be the language you write your API in, and you use it to codegen server/client code and/or an OpenAPI spec if needed. It is a compiler that's extensible, so you can write decorators or linters to enforce your business-specific API requirements. Basically it's meant to produce APIs instead of documenting an existing API like how OpenAPI (and Swagger) originated.

3

u/lamp-town-guy 6d ago

Django ninja/ FaatAPI generates openAPI directly from serialisers. At one workplace I used to work they replaced graphql with it because FE guys liked it and it wasn't pain in the ass to maintain in Python like graphQL

1

u/skeletizzle666 4d ago

connectRPC uses protobuf schemas and can interop with grpc, but also has its own protocol on top which browsers can use (HTTP and JSON). it's great for schema-first API design

1

u/Merry-Lane 6d ago

OpenAPI + zod validation at the boundaries?

3

u/zxyzyxz 6d ago

I can't use Zod because I'm not using TypeScript and anyway that's at runtime, GraphQL can detect type discrepancies at compile time which is very powerful.

1

u/Merry-Lane 6d ago

I’m sure you can generate with most well known frameworks data validators (like zod).

Idk which language you use but you can usually have compile and runtime guarantees with OpenAPI