Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
h3rp1d3v5232yWeird graphql eager loading and error handling?
Can't think of anything that can go well -
hitko31482yDon't do it. tRPC is like going back to REST, except instead of writing GET /products?page=3 you write listProducts({ page: 3 }). The "type safety" tRPC talks about comes from importing server-side type definitions into your client, you don't need a fancy library to do that. Input validation requires third-party libraries like yup, again you don't need tRPC to use those. tRPC code is awful; with graphql you just need to define a single resolver for each nested field and graphql takes care of invoking it when needed, with tRPC you need to manually invoke the code to resolve nested fields wherever you need them - or use ORM like prisma, which is again something you can use without tRPC. Graphql lets you specify which nested fields to resolve, tRPC doesn't. Graphql clients can automatically normalise and update data in cache, tRPC can't do any kind of normalisation nor optimistic cache updates. If you want to simplify your code, just use type-graphql.
-
hitko31482yHere's some more reasons why tRPC is a bad idea:
- tRPC forces you to have tightly-coupled server and client codebase, so you can't have different people working on front- and back-end code without interfering with each other
- tRPC passes parameters as url-encoded JSON, so instead of "?page=3" your request looks like "?input=%7B%22page%22%3A3%7D"
- tRPC has no way to handle file uploads
- you're limited to web browser and typescript, if you ever need to connect to your tRPC API from elsewhere you'll have to write the client yourself and there's a very limited documentation on how to do that + you won't get any type safety, graphql clients (with codegen) provide type safety in most languages -
hitko31482yAll in all tRPC is a quick and dirty solution for small projects where you need to make something in a week and then forget about it, for anything bigger it's going to be more of a bottleneck than a solution. Even the tRPC authors themselves recommend not migrating existing [graphql] projects to tRPC if the project is anything more than a simple, thightly-coupled typescript monorepo.
-
yehaaw26042y@hitko Thank you so much for your input! I’ll have to investigate this further it seems.
Related Rants
Anyone moved from GraphQL to tRPC? Thinking about doing that. I wonder about the struggles I might face while I do the refactoring.
question
graphql
trpc