Skip to content

Instantly share code, notes, and snippets.

@Kliton
Created September 26, 2022 23:45
Show Gist options
  • Select an option

  • Save Kliton/d697150ed7d91240efe69a7cb3c30672 to your computer and use it in GitHub Desktop.

Select an option

Save Kliton/d697150ed7d91240efe69a7cb3c30672 to your computer and use it in GitHub Desktop.

Why our company switched from Golang + GraphQL to Typescript + tRPC + Prisma

Our company journey with tRPC and GraphQL

Introduction

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

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

Note: I've write an article that shows how to set up a gRPC server with Golang step by step. Check it out

Verbosity: the problem we faced in our company ( happens also to solo-devs or small companies )

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 ):

  1. Definition of structures and queries with the ORM ( and there is a lot of repetitive code there )
  2. Definition of GraphQL schema.
  3. Implementation of GraphQL resolvers.
  4. Codegen for GraphQL queries and mutation for React frontend ( with typescript )
  5. 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.

What is tRPC

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.

What is Prisma

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

Our choice: drop Golang and GraphQL and use Typescript ( node ) with tRPC + Prisma

Using Prisma and typescript with tRPC we can redefine our process:

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

  2. Use the tRPC APIs on the frontend ( fully typesafe because of typescript )

    That's it.

What we are gaining from this choice

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

Conclusion

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment