Skip to content
This repository was archived by the owner on Dec 19, 2022. It is now read-only.

Chapter 1) The Router API #24

Closed
KATT opened this issue Feb 1, 2022 · 1 comment · Fixed by #33
Closed

Chapter 1) The Router API #24

KATT opened this issue Feb 1, 2022 · 1 comment · Fixed by #33
Assignees
Labels
❕ RFC Request for comments - please comment!

Comments

@KATT
Copy link
Member

KATT commented Feb 1, 2022

The router API

Challenges with the current implementation

  • TypeScript performance. Each procedure added creates a new Router that TypeScript chokes on as the underlying complexity grows non-linearly with each added procedure - each procedure basically has its "own instance" within the compiler even if it's flattened and unaffected at runtime.
  • I find that those queries are hard/unintuitive to write, I find myself counting parentheses and curly brackets all too often. Arguably, your suggestions with the resolver API could also address this.
  • No CMD+click

Suggested implementation

  • Flat router
  • No automatic prefixing (breaks jump to definition / CMD+click)
import { z } from 'zod';
import { initTRPC } from './trpc/server';

const trpc = initTRPC<Context>();

const postRouter = trpc.router({
  queries: {
    postById: null as any /* resolver implementation is a separate discussion */
    postAll: null as any /* resolver implementation is a separate discussion */
  },
  mutations: {
   postAdd: null as any /* resolver implementation is a separate discussion */
});

const userRouter = trpc.router({
  queries: {
    userAll: null as any /* resolver implementation is a separate discussion */
  },
);

const appRouter = trpc.mergeRouters(
  postRouter, 
  userRouter, 
  // ...
)
@KATT KATT added the ❕ RFC Request for comments - please comment! label Feb 1, 2022
@KATT KATT pinned this issue Feb 1, 2022
@KATT
Copy link
Member Author

KATT commented Apr 11, 2022

Closed by #33

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❕ RFC Request for comments - please comment!
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant