0

I'm migrating standard REST Api to tRPC. I had the endpoints:

  • GET /api/auth (get auth info about a user)
  • POST /api/auth (auth a user)

In the tRPC router, I cannot add query and mutation to the same route. Obviously, I have an error TS1117: An object literal cannot have multiple properties with the same name. for an object I pass to the router.

auth: authedProcedure
  .query(({ ctx }) => ({ account: ctx.account })),

auth: publicProcedure
  .mutation(({ ctx }) => ({ foo: 'bar' })),

Can query and mutation be combined for one route (using different procedures)?

How to deal with this case?

Evgeny
  • 631
  • 6
  • 17
  • Give them different names. – super May 29 '23 at 08:00
  • @super, of course, it will work. I'm asking if there is something built-in for these cases. – Evgeny May 29 '23 at 08:10
  • 1
    You typically don't think in terms of routes and methods when using RPC. There are just methods with names. So `GET/POST/PUT` to `/foo` would typically become `getFoo/createFoo/updateFoo` or something similar. I would just try to give them some descriptive name to help document what the difference is between the two. – super May 29 '23 at 09:26
  • @super It's exactly what I realized recently. RPC are just typical functions and I don't need to care about GET and POST. Hard to switch mentally after 15 years :) Thanks for your help! – Evgeny May 29 '23 at 10:11

0 Answers0