Denam
Denam11mo ago

How do you make use of custom input validation?

I have an input validation middleware, to parse my input based on some values in ctx.
export function contextInputValidation(
callback: (options: { ctx: Context }) => zod.Schema,
) {
return middleware(async ({ next, ctx, rawInput }) => {
const schema = callback({ ctx });
const input = schema.parse(rawInput);
const stack = await next({
rawInput: input,
});

return stack;
});
}
export function contextInputValidation(
callback: (options: { ctx: Context }) => zod.Schema,
) {
return middleware(async ({ next, ctx, rawInput }) => {
const schema = callback({ ctx });
const input = schema.parse(rawInput);
const stack = await next({
rawInput: input,
});

return stack;
});
}
However, how can I pass the value of this input down? rawInput and input are not available in the mutation method.
request
.use(contextInputValidation(({ ctx }) => schema))
.mutation(async ({ ctx, input, rawInput }) => {
...
})
request
.use(contextInputValidation(({ ctx }) => schema))
.mutation(async ({ ctx, input, rawInput }) => {
...
})
0 Replies
No replies yetBe the first to reply to this messageJoin