Links & Request Batching
Similar to urql's exchanges or Apollo's links. Links enables you to customize the flow of data between tRPC Client and the tRPC-server.
Request Batching
Request batching is automatically enabled which batches your requests to the server, this can make the below code produce exactly one HTTP request and on the server exactly one database query:
ts
ts
Customizing data flow
The below examples assuming you use Next.js, but the same as below can be added if you use the vanilla tRPC client
Setting a maximum batch size
This limits the number of requests that can be sent together in batch ( useful to prevent the url from getting too large and run into HTTP error 413 ).
server.tsts
server.tsts
Disabling request batching
1. Disable batching on your server:
In your [trpc].ts:
pages/api/trpc/[trpc].tsts
pages/api/trpc/[trpc].tsts
2. Use batch-free link in your tRPC Client
pages/_app.tsxtsx
pages/_app.tsxtsx
Using a splitLink to control request flow
Disable batching for certain requests
1. Configure client / _app.tsx
pages/_app.tsxtsx
pages/_app.tsxtsx
2. Perform request without batching
MyComponent.tsxtsx
MyComponent.tsxtsx
or:
client.tsts
client.tsts
Creating a custom link
pages/_app.tsxtsx
pages/_app.tsxtsx