P
Prisma•2mo ago
chad3814

Introspection in the client extensions

Say I have a client exension:
new PrismaClient({
}).$extends({
query: {
$allModels: {
findFirst({ model, args, query }) {
return query(args);
}
}
}
})
new PrismaClient({
}).$extends({
query: {
$allModels: {
findFirst({ model, args, query }) {
return query(args);
}
}
}
})
The model here is just a string. How can I figure out if there's a unique constraint in the args, and what it is? Anyway to determine if the model has an @id field? I want to make something smarter than just a generic query cache.
3 Replies
Nurul
Nurul•2mo ago
Hey @chad3814 👋
How can I figure out if there's a unique constraint in the args, and what it is?
You would need to use Prisma.dmmf property to get this information.
import { PrismaClient, Prisma } from "@prisma/client";

console.log(JSON.stringify(Prisma.dmmf, null, 2));
import { PrismaClient, Prisma } from "@prisma/client";

console.log(JSON.stringify(Prisma.dmmf, null, 2));
Please note that dmmf is an internal property and there maybe breaking changes in minor versions.
chad3814
chad3814OP•2mo ago
Please note that dmmf is an internal property and there maybe breaking changes in minor versions.
Any plans to make a public property?
Nurul
Nurul•2mo ago
I don't think there are any immediate plans to make DMMF public yet
Want results from more Discord servers?
Add your server