NazCodeland
NazCodeland
TtRPC
Created by NazCodeland on 6/16/2023 in #❓-help
merging other routers to appRouter
Hey everyone, I am using the https://icflorescu.github.io/trpc-sveltekit package in my SvelteKit project. My question is not related to that package (at least I don't think it is) I figured I mention it since it might be related and I just don't know... I am wondering if I have this code,
// router/router.ts
import type { Context } from '$server/trpc/context';
import { initTRPC } from '@trpc/server';

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

export const publicProcedure = tRPC.procedure;
export const appRouter = tRPC.router;

export type AppRouter = typeof appRouter;
// router/router.ts
import type { Context } from '$server/trpc/context';
import { initTRPC } from '@trpc/server';

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

export const publicProcedure = tRPC.procedure;
export const appRouter = tRPC.router;

export type AppRouter = typeof appRouter;
and say I also have
// routers/user.ts
import { appRouter, publicProcedure } from '$server/trpc/router';

export const userRouter = appRouter({
list: publicProcedure.query(() => {
return [];
})
});
// routers/user.ts
import { appRouter, publicProcedure } from '$server/trpc/router';

export const userRouter = appRouter({
list: publicProcedure.query(() => {
return [];
})
});
am I able to merge the userRouter onto the appRouter directly within the /router/user.ts file?
7 replies
TtRPC
Created by NazCodeland on 6/13/2023 in #❓-help
should we use tRPC for handling form submittion or not?
Hey everyone, I've started using tRPC for my API endpoints and my project is based in Svelte/SvelteKit and in that eco system we have this https://superforms.rocks/ library for handling form data. I am unsure what to choose here
6 replies
TtRPC
Created by NazCodeland on 6/9/2023 in #❓-help
if I export 'appRouter' instead of 'router' I get error
hey everyone, I have this exact setup https://icflorescu.github.io/trpc-sveltekit/getting-started I created all the files inside of /src/trpc/ besides the hooks.server.ts which is inside /src/trpc/ only difference is that inside the file router.ts I've changed the variable name router in this line:
export const router = t.router({...})
export const router = t.router({...})
to
export const appRouter = t.router({...})
export const appRouter = t.router({...})
and then at the bottom
export type Router = typeof router;
export type Router = typeof router;
changed to
export type Router = typeof appRouter;
export type Router = typeof appRouter;
and changed the file /src/trpc/router.ts to /src/trpc/appRouter.ts and inside of /src/trpc/client.ts changed
import type { Router } from '$lib/trpc/router';
import type { Router } from '$lib/trpc/router';
to
import type { Router } from '$lib/trpc/appRouter';
import type { Router } from '$lib/trpc/appRouter';
inside of /src/hooks.server.ts I've changed the import
import { router } from '$lib/trpc/router';
import { router } from '$lib/trpc/router';
to
import { appRouter } from '$lib/trpc/appRouter';
import { appRouter } from '$lib/trpc/appRouter';
and changed this line
export const handle: Handle = createTRPCHandle({
appRouter,
createContext,
export const handle: Handle = createTRPCHandle({
appRouter,
createContext,
to
export const handle: Handle = createTRPCHandle({
router,
createContext,
export const handle: Handle = createTRPCHandle({
router,
createContext,
4 replies