I wanna share with you the journey that brings our company to tRPC and GraphQL.
I work in an Italian consulting company that mostly makes ERP ( Enterprise resource planning ) software for customers.
Those types of software generally are for 50% to 70% CRUD operations.
So over the years we've tried to automate everything we can for CRUDs because they're boring and repetitive and using the time saved on business logic.
Our stack for the past 3 years was this ( I've simplified it a bit )
Backend ( mostly serverless on GCP with CloudRun/CloudFunctions )
- Golang
- GraphQL ( gqlgen go library for building GraphQL server with a schema first approach )
- gRPC ( for internal communication between microservices )
- Pub/Sub ( for internal async communication between microservices )
Frontend
- React (NextJS)
- Material UI ( or other UI toolkit )
- GraphQL ( with codegen )
Note: I've write an article that shows how to set up a gRPC server with Golang step by step. Check it out
In the backend we were using an ORM for GoLang ( called Bun ) and GqlGen library for generating schema first GraphQL servers.
Our process was this ( simplified ):
- Definition of structures and queries with the ORM ( and there is a lot of repetitive code there )
- Definition of GraphQL schema.
- Implementation of GraphQL resolvers.
- Codegen for GraphQL queries and mutation for React frontend ( with typescript )
- Usage of generated queries/mutations on the frontend
In this process the first and the third step are incredibly verbose and boring for CRUD operations.
tRPC is a light library that lets you build fully typesafe APIs without need for schemas or code generation tools.
It allows type sharing between client and server.
Currently GraphQL is the dominant way to implement typesafe APIs in TypeScript (and it's amazing!). Since GraphQL is designed as a language-agnostic specification for implementing APIs, it doesn't take full advantage of the power of a language like TypeScript.
If your project is built with full-stack TypeScript, you can share types directly between your client and server, without relying on code generation.
Prisma is an ORM that helps app developers build faster and make fewer errors.
It consists of the following parts:
- Prisma Client : Auto-generated and type-safe query builder for Node.js & TypeScript
- Prisma Migrate : Migration system
- Prisma Studio : GUI to view and edit data in your database
https://www.youtube.com/watch?v=EEDGwLB55bI&feature=emb_title&ab_channel=Prisma
Using Prisma and typescript with tRPC we can redefine our process:
-
Create the Prisma schema: we define our application models Prisma will create for us everything: queries, structures, and tRPC APIs with the Prisma-tRPC-generator
-
Use the tRPC APIs on the frontend ( fully typesafe because of typescript )
That's it.
This new stack ( tRPC + Prisma + Typescript ) for the backend part is:
- improving quality of code
- speed of delivery
- happiness of our devs
- less repetitive and boring coding
We're leaving Golang ( except for some microservices, because we still love Golang ).
We're leaving GraphQL ( note that Prisma can generate also a GraphQL server with all the crud operations ).
GraphQL is still a great tool but sometimes is overkill and there is no need for it in small scale project.
We're really happy with this choices that we made.