65 points · by mariuz · 3y ago · 55 comments
One difference is syntax: Phero leverages the TS compiler api to generate parsers for your backend functions. It will parse input and output of your api functions, automatically, based on the types you define for your functions. It will generate a declaration file of your api and generate an RPC style client SDK for your frontend. Another difference is that it aims to be more batteries includes.
[1] https://github.com/phero-hq/phero
Comparison: https://phero.dev/docs/comparisons/tRPC
> Know when you break compatability with the frontend, before even running it: TypeScript has your back.
Do you? Your front-end and back-end, regardless if they use the same source for their interface contract, aren't deployed as a unit. At least not always, and not in the single page application use cases you're targeting.
How do you handle versioning and protocol compatibility? Across all these frameworks, it feels like a footgun your users will discover on their own.
We use Phero extensively in mobile apps projects, so we know the pain of maintaining API versions and backward compatibility hell.
Phero generates a declaration file with all functions you expose, and bundles dependent domain models (interfaces, type aliases, enums, etc) with it. Currently there's only one version. Our plan is to let users pin versions of this declaration file (we call it the manifest file).
Then we build cli commands to compare them and actually tell if they are compatible. This way you know if it's safe to deploy a new version of your API without breaking existing clients. These are all future plans of course, but in the scope of the project.
Exactly. tRPC and other projects alike don’t provide you an actual API that you can later consume, but an RPC “glue”
One big difference in philosophy here is that tRPC is not designed to be used for cases where you have third party consumers. It's built for situations where you control both ends. (That said, you can use trpc-openapi for the endpoints that are public)
On versioning: it's 2023 & in most cases, you can solve versioning in other ways than maintaining old API versions indefinitely. For RN there's OTA, for web you just need to reload the page or "downgrade" your SPA-links to a classic link to get a new bundle (did an example here https://twitter.com/alexdotjs/status/1627739926782480409)
Also, we'll release tooling to help keeping track of changes in cases where you can't update the clients as easily.
GraphQL is amazing but it isn't a silver bullet either, it has its own complexity that you have to accept as well.
This means you won't be getting the same real-time experience/feedback you get with tRPC, because you will still be waiting for Phero's compiler to complete the build
I was expecting something like that to emerge and initially wanted to go into that direction with Garph (see my comment below) but we ultimately decided that a code-gen does not give you the same amazing feeling so we ended building a pure TypeScript library
Good luck with Phero in any case!
In our experience the latency between changing something in your API, and seeing compile errors arise in the client is just a few seconds. And this only matters when your API contract changes, which is of course not always. Not a biggy in our eyes. In order to run, you'd need to compile TS anyways. :)
In our opinion this is well worth the "magic" Phero adds: it will work with plain TS. No "t.string" like apis to build your apis/models. Matter of taste I guess :)
We've "had" end-to-end typesafety with codegen tools openapi/swagger and graphql etc.
However, the big issue with a lot of those tools is that you end up having to manage this compile step.
The real magic of trpc is exactly this point about it being without a compiler, where the types are derived from the very same typescript files - this is what gives it this immediacy and feeling of it being instant and not having to deal with a compile step.
I've always wondered whether we'd get the same benefits and niceties with a really streamlined compiling approach - perhaps something like phero. But it's just a little harder of a sell compared to the built-in typesafety you get from trpc
NextJS and RemixJS have interesting approaches to gluing clients and server together. Microsoft Blazor Server is an extreme version of where things are headed. Just call C# functions and the UI is surgically updated as needed over SignalR. I haven't found any other stacks take it that far yet.
- ts-rest (https://ts-rest.com)
- Garph (https://github.com/stepci/garph)
- zodios (https://www.zodios.org)
- Kysely (https://github.com/koskimas/kysely)
[0] https://trpc.io/docs/awesome-trpc#-open-source-projects-usin...
You get all the benefits of tRPC and all the benefits of GraphQL in one package. Garph can also be used to replace graphql-codegen in your stack with statically inferred types
https://github.com/stepci/garph
(disclaimer: I'm author of Garph)
You have a TypeScript backend and TypeScript frontend and want to expose the GraphQL API to third-party consumers or add a mobile app into the mix
And since Garph produces a spec-compatible GraphQL API you can use it with existing tools like Hasura, Apollo, Stellate, AWS AppSync, etc.
tRPC is a great choice if you want to call server functions from the client without overhead in a type-safe way. However, with React Server Components, I doubt you will need tRPC for this use-case anymore
Our concept was: take the amazing developer experience and end-to-end type-safety of tRPC but give you an actual, spec-compatible GraphQL API, that you can expose and others can use and that also works with existing GraphQL tools
This is how Garph was born!
There are a couple of differences: Garph is easier to use than Pothos, Garph fully supports circular references (no workarounds!) and Garph solves type-safety for clients without the need for code-gen. We also offer a compatible client for React/Next.js based on GQty (formerly GQless) for the best experience
Pothos is great for backend-only applications and if you need advanced features such as Relay right now. Garph is great if you want the best possible developer experience and type-safety on both ends of your stack
Have you used it on a larger project?
What does this get me that gRPC + Protobuf to generate a Typescript client wouldn't?
Edit: Ah. I see, you can use Typescript to define the IDL vs. learning Protobuf, Smithy, ...
Not sure I would take the trade-off. I like having the option of using something other than Typescript for my back-end. The dev experience isn't compelling enough for me. Contract changes are not an area I iterate on so often that a small delay in re-generating the client from an IDL causes me to grab for this dependency.
The frontend and backend get code generated differently. The backend is all interfaces (which, through some Nestjs magic get translated into protobufs) and the frontend is all objects. So on the frontend, you're expected to write:
const message = new MyRequest().setName('Bob').setFoo('bar');
On the backend, you'd just write: const message = { name: 'Bob', foo: 'bar' }
It's not a big deal, but it's weird. The backend ends up being more/overly strict about all values being set when you might just be fine with the default zero/empty values.Also, using a `oneof` field is correctly typed on the frontend as
myfield: TypeA | TypeB | TypeC`
But the backend gives you myfield: {a: TypeA | undefined, b: TypeB | undefined, c: TypeC | undefined}
For a future project, I'd look into buf or Connect instead of the default gRPC code generators, but for now, I just need to get stuff done. myfield: TypeA | TypeB | TypeC
But what about when the `oneof` has multiple variants with the same base type? Like: message User {
oneof contact_info {
string email = 1;
string phone_number = 2;
}
}
Does this get compiled down to `contact_info: string | string` on the frontend? How do you tell which variant was used without encoding the discriminant?Have you tried running gRPC in the browser? How was the experience?
https://web.archive.org/web/20230307144631/https://www.robin...
I just thought that for avoiding having to use a generator step there's a lot of glue that's being written.