1
yehaaw
1y

Anyone moved from GraphQL to tRPC? Thinking about doing that. I wonder about the struggles I might face while I do the refactoring.

Comments
  • 1
  • 0
    Weird graphql eager loading and error handling?
    Can't think of anything that can go well
  • 2
    Don'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.
  • 1
    Here'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
  • 1
    All 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.
  • 0
    @hitko Thank you so much for your input! I’ll have to investigate this further it seems.
Add Comment