echobind / bisonapp

A Full Stack Jamstack in-a-box brought to you by Echobind
MIT License
589 stars 29 forks source link

feat: Migrate the backend from GraphQL to tRPC #282

Closed alexanderson1993 closed 1 year ago

alexanderson1993 commented 1 year ago

Changes

This is a major architectural change that's difficult to summarize. I decided to do the entire migration in a single PR since GraphQL itself is so deeply integrated with the rest of Bison. A good portion of the changes are documentation, though, so hopefully reviewing everything else isn't too bad.

First, this PR removes code, config, and dependencies related to GraphQL. That includes Nexus, GraphQL Codegen, Apollo Server, and Apollo Client. This also includes anything that references the files generated by Nexus and GQL Codegen.

Next, I created a tRPC router and middleware for authenticated procedures. I created the userRouter and replicated all of the queries and mutations that existed in the GraphQL schema. After wiring it up to an API route, I set up the tRPC client and replaced all the GraphQL queries with tRPC calls, making adjustments as necessary to make everything behave nicely.

I also rewrote the test files using a new trpcRequest helper, which lets you optionally pass a user record to make the request.

Once I confirmed the app was generating correctly, I updated the hygiene templates to use tRPC, updated the ReadMe and other documentation.

Checklist