Open timvandam opened 1 month ago
This could integrate nicely with mutation scopes to ensure that a subset of mutations all share the same scope (e.g. <some-resource>-<some-resource-id>
) https://tanstack.com/query/latest/docs/framework/react/guides/mutations#mutation-scopes
Describe the feature you'd like to request
I would like to be able to capture arguments at the router-level and have these propagate down to procedures. This can help deduplicate code but most importantly could make it easier to invalidate nested routers more precisely.
For instance, if we have a resource named
Post
we could create a router with an argument namedid
. Then, rather than invalidating the fullPost
router, we could invalidate the router for one specificid
. This would make it much easier to accurately invalidate exactly what you want to invalidate.Currently, your options would be to either manually invalidate all queries for
Post
that requireid
one by one, or to just invalidate the fullPost
router, for anyid
. They are both suboptimal; the former is not resistant to the scope of your router expanding, while the latter invalidates over eagerlyDescribe the solution you'd like to see
In the backend a simple
.input
available on routers would do. The parsed input would then be made available to all inner procedures.On the front-end, the proxy would now capture function calls to reference parameterized routers. E.g. we could use
trpc.post({ id: 'xyz'}).mutate({ title: 'Hello, world!' })
andutils.post({ id: 'xyz'}).invalidate()
.Describe alternate solutions
As mentioned, currently you could invalidate the full router or trust yourself enough (I don't) to always keep every mutation up to date
Additional information
No response
π¨βπ§βπ¦ Contributing
Funding