Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prototype] switch backend from graphql to trpc #556

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lihebi
Copy link
Collaborator

@lihebi lihebi commented Sep 30, 2023

Rationale

Web APIs are hard to work with:

  • Working with GraphQL is very verbose and lacks type safety. As a result, updating APIs is a very slow process. We need to define a schema and then implement the backend resolvers. In the front end, we need to specify the schema again. There's no type-safety involved; you have to manually keep sync of backend-schema, backend-functions, frontend-schema, and frontend-calls.

  • REST is simpler but still lacks type safety. It is up to the developer to remember the /api/path/to/handler and the ?params=... and keep the frontend/backend in sync.

The real way of frontend/backend APIs should be remote procedure calls (RPCs). One simply defines a function at the backend and calls it from the front-end. How the call happens should be abstracted away. We have two RPCs: gRPC and tRPC.

  • gRPC is designed to allow communication among backend servers. It seems to be pretty awkward to make frontend to talk to backend (e.g., via gPRC-web or connectrpc). Both take significant work to set up, as far as I can tell.

  • tRPC is the closest to what we need. A backend function is callable from the front-end with minimal scaffolding and full type-safety.

About this PR

This PR is a prototype to switch from Graphql to tRPC. This PR only implements the server API. TODOs along this line:

  • Call /trpc endpoints from the frontend.
  • Since the desktop app and web app have different APIs, we likely need to get the desktop/web app fully separated first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant