P
Prisma•4mo ago
IH

prisma use middleware

Hi I am trying to collect logs for args before query request. However, in case of USE (middleware), it is checked as deprecated, is it possible that the feature will be removed in future updates? If so, I was wondering where I can collect ARGS logs for all query requests as an alternative to the middleware.
2 Replies
jonfanz
jonfanz•4mo ago
We have no plans to remove middleware at this time. It's safe to use 🙂
RaphaelEtim
RaphaelEtim•4mo ago
Hi @IH 👋 We recommend using Prisma Client Extension as an alternative to middleware. Prisma Client Extension provide a more flexible and type-safe way to extend the functionality of the Prisma Client. To collect logs for arguments before a query request using Prisma Client Extension, you can use the query component type.
const prisma = new PrismaClient();

const extendedPrisma = prisma.$extends({
query: {
$allModels: {
$allOperations({ model, operation, args }) {
console.log('Query Arguments:', args);
return next(args);
}
}
}
});

// Use extendedPrisma for your queries
extendedPrisma.user.findMany();
const prisma = new PrismaClient();

const extendedPrisma = prisma.$extends({
query: {
$allModels: {
$allOperations({ model, operation, args }) {
console.log('Query Arguments:', args);
return next(args);
}
}
}
});

// Use extendedPrisma for your queries
extendedPrisma.user.findMany();
See this section of the documentation.
Prisma Client extensions: query component | Prisma Documentation
Extend the functionality of Prisma Client, query component
Want results from more Discord servers?
Add your server