OtterSwims996
Explore posts from serversUnable to set up a client side subscription to a trpc route that supports websockets
I have been able to fix this issue by using a function to return the correct link in the links array.
It seems that the links are something that are mainly evaluated on the client side, and wsLink as well as httpBatchLink are "terminating links" which means that we cannot consecutively put a wslink after a httpBatchLink or vice versa.
I borrowed a code snippet from this example project which returns the right link based on the browser having a window.
https://github.com/trpc/examples-next-prisma-websockets-starter/blob/c666de6367d7449d4108e5e384da043c4f93a5d5/src/utils/trpc.ts#L21-L43
Its also possible to return the right link based on the operation type as is done here:
https://github.com/apollographql/subscriptions-transport-ws/issues/333
5 replies
Unable to set up a client side subscription to a trpc route that supports websockets
it seems that httpbatchlink is a terminating link that is causing my request to never be routed to the wslink that is in my links array: https://trpc.io/docs/client/links#the-terminating-link
so i will have to use splitlink or some conditional logic like i see is used here in this sample project https://github.com/trpc/examples-next-prisma-websockets-starter/blob/077367508a7dcda504170b48bc7b6c65457f90c6/src/utils/trpc.ts#L18-L40
5 replies