santi
santi
TtRPC
Created by santi on 4/12/2024 in #❓-help
Is it possible to get the procedure name / id in middleware?
I want to create a caching middleware that in some routes, stores a cache key that contains the route id (example: catalog.product.findMany) and the input (example: { categories: shirts }). It's not clear to me if this is possible.
8 replies
TtRPC
Created by santi on 4/8/2024 in #❓-help
Create client that is used in every request, without re-creating client
Hi all, Consider the following
export const createContextInner = async ({
req,
res,
}: {
req?: Context['req']
res?: Context['res']
}): Promise<Context> => {
const app = await NestFactory.createApplicationContext(AppModule)
return {
app,
prisma,
req,
res,
supabaseServerClient: null,
user: null,
}
}
export const createContextInner = async ({
req,
res,
}: {
req?: Context['req']
res?: Context['res']
}): Promise<Context> => {
const app = await NestFactory.createApplicationContext(AppModule)
return {
app,
prisma,
req,
res,
supabaseServerClient: null,
user: null,
}
}
This is annoying in local development because it needs to create the nest app for every request. The same thing with the prisma client. We'd like to create this once and use in every request. Is this possible?
6 replies
TtRPC
Created by santi on 4/27/2023 in #❓-help
Bug where 2 requests are fired at once. TRPC batches them. Can I cancel the 2nd via ProcedureOption?
Hey all. I have a bug where my app fires two identical requests at the same time. This happens do to some weird upstream auth listener logic. Ideally TRPC can help me mitigate this. I want to configure ProcedureOption such that it doesn't batch, but rather only lets the first request to go through. Is this possible?
const updatedCartItems = await trpcClient.user.cart.replaceCartOnAuthLoaded.mutate(
{
anonymousCartItems,
},
{
onlyOneAtATime: true,
},
)
const updatedCartItems = await trpcClient.user.cart.replaceCartOnAuthLoaded.mutate(
{
anonymousCartItems,
},
{
onlyOneAtATime: true,
},
)
4 replies
TtRPC
Created by santi on 4/4/2023 in #❓-help
How can I access ctx from inside of a procedure?
const appRouter = t.router({
helloTab: t.procedure.input(z.object({ url: z.string().url() })).mutation(async ({ input, ctx }) => {
//@ts-ignore
const tab = ctx.sender.tab
console.log(tab)
}),
});
const appRouter = t.router({
helloTab: t.procedure.input(z.object({ url: z.string().url() })).mutation(async ({ input, ctx }) => {
//@ts-ignore
const tab = ctx.sender.tab
console.log(tab)
}),
});
is something like this possible? Not working for me
2 replies
TtRPC
Created by santi on 4/4/2023 in #❓-help
Async User Call in `createContext` (context.ts) or in `isAuthed` (in trpc.ts)
4 replies
TtRPC
Created by santi on 3/27/2023 in #❓-help
Use TRPC function inside of a TRPC function
Hi all! We have a trpc query called getProduct. I want to use this getProduct query inside of another query (getCart query). Is this possible / simple as a single trpc request rather than multiple?
3 replies
TtRPC
Created by santi on 3/23/2023 in #❓-help
createProxySSGHelpers type error
8 replies