Vinnie
Vinnie
TtRPC
Created by Vinnie on 5/12/2024 in #❓-help
Infer context from procedure after middleware
Okay I didn't come up with a direct solution, but I did solve it in a different way. Instead of just having the handler functions be in separated files. These -> .mutation(handlerFunc) I moved the whole creation of the procedure into seprate files. This way you can put the handler function directly into the .mutation call. This way the options (so also the context) are correctly inferred and the need to import the Context type becomes unnecessary.
export const getPreferencesProcedure = privateProcedure.query(
async ({ ctx }) => {
const { viewer } = ctx;
// /\
// ||
// Viewer

// ... rest of code
}
);
export const getPreferencesProcedure = privateProcedure.query(
async ({ ctx }) => {
const { viewer } = ctx;
// /\
// ||
// Viewer

// ... rest of code
}
);
Hope this helps other people witht he same problem :)
4 replies