Call multiple TRPC endpoints from onSuccess()?
I would like to create an API chain for analysing a geographic area where one successful API call can lead to multiple new API's being called to render the components in the right orders for the user. This works really well for single API calls, but when combining multiple of them together to be triggered at a onSuccess() call, the trpc combines them all together instead of taking them one by one.
Does anyone know how to solve this?
7 Replies
you're using batching
HTTP Batch Link | tRPC
httpBatchLink is a terminating link that batches an array of individual tRPC operations into a single HTTP request that's sent to a single tRPC procedure.
read the above and https://trpc.io/docs/client/links/splitLink
Split Link | tRPC
splitLink is a link that allows you to branch your link chain's execution depending on a given condition. Both the true and false branches are required. You can provide just one link, or multiple links per branch via an array.
you should be able to just
await
them in orderThanks @alexkatt , this httpBatchLink was exactly the documentation I was looking for!!
How would that kind of structure look like @sachinraja ? Keen to give it a try!
sorry i misunderstood what you were asking - alex's solution works for what you want here
why donβt you want them to be batched though?
The polygon that I am sending from my frontend is about 300kb, so if I batch these endpoints together I am hitting the cap of 1MB max limit of TRPC (and I didn't manage to figure out how to increase it)