File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed
Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 11/**
22 * This is the client-side code that uses the inferred types from the server
33 */
4- import { createTRPCClient , httpBatchLink } from '@trpc/client' ;
4+ import { createTRPCClient , unstable_httpBatchStreamLink } from '@trpc/client' ;
55/**
66 * We only import the `AppRouter` type from the server - this is not available at runtime
77 */
@@ -10,7 +10,7 @@ import type { AppRouter } from '../server/index.js';
1010// Initialize the tRPC client
1111const trpc = createTRPCClient < AppRouter > ( {
1212 links : [
13- httpBatchLink ( {
13+ unstable_httpBatchStreamLink ( {
1414 url : 'http://localhost:3000' ,
1515 } ) ,
1616 ] ,
@@ -34,3 +34,9 @@ console.log('Created user:', createdUser);
3434const user = await trpc . user . byId . query ( '1' ) ;
3535// ^?
3636console . log ( 'User 1:' , user ) ;
37+
38+ const iterable = await trpc . examples . iterable . query ( ) ;
39+
40+ for await ( const i of iterable ) {
41+ console . log ( 'Iterable:' , i ) ;
42+ }
Original file line number Diff line number Diff line change @@ -32,6 +32,14 @@ const appRouter = router({
3232 return user ;
3333 } ) ,
3434 } ,
35+ examples : {
36+ iterable : publicProcedure . query ( async function * ( ) {
37+ for ( let i = 0 ; i < 3 ; i ++ ) {
38+ await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
39+ yield i ;
40+ }
41+ } ) ,
42+ } ,
3543} ) ;
3644
3745// Export type router type signature, this is used by the client.
Original file line number Diff line number Diff line change @@ -4,7 +4,11 @@ import { initTRPC } from '@trpc/server';
44 * Initialization of tRPC backend
55 * Should be done only once per backend!
66 */
7- const t = initTRPC . create ( ) ;
7+ const t = initTRPC . create ( {
8+ experimental : {
9+ iterablesAndDeferreds : true ,
10+ } ,
11+ } ) ;
812
913/**
1014 * Export reusable router and procedure helpers
You can’t perform that action at this time.
0 commit comments