trpc / v10-playground

tRPC v10 procedure play
https://stackblitz.com/github/trpc/v10-playground?file=src%2Fserver%2Findex.ts,src%2Fclient.ts,src%2Fserver%2Frouters%2FpostRouter.ts&view=editor
13 stars 3 forks source link

Resolver definition API too terse? #20

Closed esamattis closed 2 years ago

esamattis commented 2 years ago

The input and resolver are now just positional arguments

trpc.resolver(
  trpc.zod(
    z.object({
      hello: z.string()
    })
  ),
  (params) => {
    return {
      data: {
        greeting: "hello " + params.ctx.user?.id ?? params.input.hello
      }
    };
  }
);

to me this feels bit more cryptic, especially when adding context creation too, than the current version where the resolver definition is an object. Would this be possible here as well?

trpc.resolver({
  input: z.object({
    hello: z.string()
  }),
  resolver(params) {
    return {
      data: {
        greeting: "hello " + params.ctx.user?.id ?? params.input.hello
      }
    };
  }
});

I believe the object version would be also more future proof since it is easily extendable without breaking existing apis.

KATT commented 2 years ago

Please discuss in #25