P
Prisma•5w 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•5w 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•4w 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•4w ago
I don't think there are any immediate plans to make DMMF public yet
Want results from more Discord servers?
Add your server