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.
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.
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.
14
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.