feat(20-02): add splitLink to route subscriptions to SSE httpSubscriptionLink
Replace single httpBatchLink with splitLink that routes subscription operations to httpSubscriptionLink (SSE) while keeping queries/mutations on httpBatchLink. No new packages needed — both exports are part of @trpc/client v11.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createTRPCReact } from '@trpc/react-query';
|
||||
import { httpBatchLink } from '@trpc/client';
|
||||
import { httpBatchLink, splitLink, httpSubscriptionLink } from '@trpc/client';
|
||||
import type { AppRouter } from '@codewalk-district/shared';
|
||||
|
||||
export const trpc = createTRPCReact<AppRouter>();
|
||||
@@ -7,10 +7,10 @@ export const trpc = createTRPCReact<AppRouter>();
|
||||
export function createTRPCClient() {
|
||||
return trpc.createClient({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
// In dev, Vite proxy forwards /trpc to backend
|
||||
// In prod, same-origin or configured URL
|
||||
url: '/trpc',
|
||||
splitLink({
|
||||
condition: (op) => op.type === 'subscription',
|
||||
true: httpSubscriptionLink({ url: '/trpc' }),
|
||||
false: httpBatchLink({ url: '/trpc' }),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user