maloguertin / msw-trpc

tPRC support for MSW
206 stars 20 forks source link

Support tRPC subscriptions (WebSockets) #19

Open ben-xD opened 1 year ago

ben-xD commented 1 year ago

Is your feature request related to a problem? Please describe. This package doesn't support tRPC subscriptions (websockets), for example when the client looks like:

import { createTRPCProxyClient, createWSClient, wsLink } from '@trpc/client';
import type { AppRouter } from '../path/to/server/trpc';

// create persistent WebSocket connection
const wsClient = createWSClient({
  url: `ws://localhost:3001`,
});

const client = createTRPCProxyClient<AppRouter>({
  links: [
    wsLink({
      client: wsClient,
    }),
  ],
});

Unfortunately, the client/test will time out because the http request never gets upgraded to websocket.

Describe the solution you'd like Handle the initial http request for upgrading from http to WebSocket. The request has headers:

headers@2x

Then, the package might also get another cool feature: to control when messages/event on the tRPC subscription (websocket) are sent to the client in the test.

maloguertin commented 1 year ago

Hi! This is something I'd like to support but I'm a little busy as of now. Would you be interested in making a PR?