NazCodeland
NazCodeland
TtRPC
Created by NazCodeland on 6/16/2023 in #❓-help
merging other routers to appRouter
ahh, I think there is a circular dependency going on here ... router.ts is importing the child routers which are importing variables declared in router.ts so they haven't been initialized since router.ts code hasn't run yet so they are undefined -- just taking a guess
7 replies
TtRPC
Created by NazCodeland on 6/16/2023 in #❓-help
merging other routers to appRouter
hmm inside my post.ts file
// routers/post.ts
import { routerFactory, publicProcedure } from '$server/trpc/router';

console.log('routerFactory', routerFactory);
console.log('publicProcedure', publicProcedure);
export const postRouter = routerFactory({
greeting: publicProcedure.query(async () => {
return `Hello tRPC v10 @ ${new Date().toLocaleTimeString()}`;
})
});
// routers/post.ts
import { routerFactory, publicProcedure } from '$server/trpc/router';

console.log('routerFactory', routerFactory);
console.log('publicProcedure', publicProcedure);
export const postRouter = routerFactory({
greeting: publicProcedure.query(async () => {
return `Hello tRPC v10 @ ${new Date().toLocaleTimeString()}`;
})
});
both of the console.logs returrn undefined, which is odd
7 replies
TtRPC
Created by NazCodeland on 6/16/2023 in #❓-help
merging other routers to appRouter
TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)
TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)
TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)
TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)
7 replies
TtRPC
Created by NazCodeland on 6/16/2023 in #❓-help
merging other routers to appRouter
hmm, that actually doesn't work for me, I am getting this error
9:45:45 p.m. [vite] Error when evaluating SSR module /src/server/trpc/routes/posts.ts:
|- TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)

9:45:45 p.m. [vite] Error when evaluating SSR module /src/server/trpc/router.ts: failed to import "/src/server/trpc/routes/posts.ts"
|- TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)

9:45:45 p.m. [vite] Error when evaluating SSR module /src/server/middleware/hooks.server.ts: failed to import "/src/server/trpc/router.ts"
|- TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)
9:45:45 p.m. [vite] Error when evaluating SSR module /src/server/trpc/routes/posts.ts:
|- TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)

9:45:45 p.m. [vite] Error when evaluating SSR module /src/server/trpc/router.ts: failed to import "/src/server/trpc/routes/posts.ts"
|- TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)

9:45:45 p.m. [vite] Error when evaluating SSR module /src/server/middleware/hooks.server.ts: failed to import "/src/server/trpc/router.ts"
|- TypeError: Cannot read properties of undefined (reading 'query')
at eval (C:/Users/o0/source/projects/mine/Barbercate/src/server/trpc/routes/posts.ts:6:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async instantiateModule (file:///C:/Users/o0/source/projects/mine/Barbercate/node_modules/.pnpm/vite@4.3.9_@types+node@20.3.0/node_modules/vite/dist/node/chunks/dep-e8f070e8.js:54405:9)
7 replies
TtRPC
Created by NazCodeland on 6/16/2023 in #❓-help
merging other routers to appRouter
based on my research it seems like we can't, I've opted for this solution instead,
import type { Context } from '$server/trpc/context';
import { initTRPC } from '@trpc/server';
import { userRouter } from './routes/user';
import { postRouter } from './routes/posts';

export const tRPC = initTRPC.context<Context>().create();

export const publicProcedure = tRPC.procedure;

// whenever creating new routers, import routerFactory
export const routerFactory = tRPC.router;

// import into this file child routers and add them to appRouter
export const appRouter = routerFactory({
user: userRouter,
post: postRouter,
});

export type AppRouter = typeof appRouter;
import type { Context } from '$server/trpc/context';
import { initTRPC } from '@trpc/server';
import { userRouter } from './routes/user';
import { postRouter } from './routes/posts';

export const tRPC = initTRPC.context<Context>().create();

export const publicProcedure = tRPC.procedure;

// whenever creating new routers, import routerFactory
export const routerFactory = tRPC.router;

// import into this file child routers and add them to appRouter
export const appRouter = routerFactory({
user: userRouter,
post: postRouter,
});

export type AppRouter = typeof appRouter;
if this is incorrect in a way that I can't forsee please let me know
7 replies
TtRPC
Created by NazCodeland on 6/13/2023 in #❓-help
should we use tRPC for handling form submittion or not?
ok thanks for the help r-i-c-h
6 replies
TtRPC
Created by NazCodeland on 6/13/2023 in #❓-help
should we use tRPC for handling form submittion or not?
I don't know to much of either library so I can't really say. From my understand so far, superforms library is primary meant to handle form data and not make api endpoints
6 replies
TtRPC
Created by NazCodeland on 6/9/2023 in #❓-help
if I export 'appRouter' instead of 'router' I get error
sorry for the late response just seeing this, I managed to fix it, in my hooks.server.ts(I'm using Svelte/SvelteKit) I had
export const handle: Handle = createTRPCHandle({
appRouter,
createContext
});
export const handle: Handle = createTRPCHandle({
appRouter,
createContext
});
instead of
export const handle: Handle = createTRPCHandle({
router: appRouter,
createContext
});
export const handle: Handle = createTRPCHandle({
router: appRouter,
createContext
});
My typescript wasn't working properly so that wasn't even throwing a warning, but since fixing my typescript I noticed it
4 replies