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 { createTRPCReact } from '@trpc/react-query';
|
||||||
import { httpBatchLink } from '@trpc/client';
|
import { httpBatchLink, splitLink, httpSubscriptionLink } from '@trpc/client';
|
||||||
import type { AppRouter } from '@codewalk-district/shared';
|
import type { AppRouter } from '@codewalk-district/shared';
|
||||||
|
|
||||||
export const trpc = createTRPCReact<AppRouter>();
|
export const trpc = createTRPCReact<AppRouter>();
|
||||||
@@ -7,10 +7,10 @@ export const trpc = createTRPCReact<AppRouter>();
|
|||||||
export function createTRPCClient() {
|
export function createTRPCClient() {
|
||||||
return trpc.createClient({
|
return trpc.createClient({
|
||||||
links: [
|
links: [
|
||||||
httpBatchLink({
|
splitLink({
|
||||||
// In dev, Vite proxy forwards /trpc to backend
|
condition: (op) => op.type === 'subscription',
|
||||||
// In prod, same-origin or configured URL
|
true: httpSubscriptionLink({ url: '/trpc' }),
|
||||||
url: '/trpc',
|
false: httpBatchLink({ url: '/trpc' }),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user