[prototype] switch backend from graphql to trpc #556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
/trpc
endpoints from the frontend.