Dev__
07/15/2021, 7:39 AMrejectOnNotFound
enabled on a global level for all findFirst
and findUnique
queries but it doesnt seem to work. I am using nestjs
tho so the prisma
configuration is different
// prisma config
export class PrismaService extends PrismaClient<LogOptions> implements OnModuleInit, OnModuleDestroy {
constructor() {
super({
log: [
{
emit: 'event',
level: 'query'
}
],
rejectOnNotFound: {
findFirst: () => new Error('error'),
findUnique: () => new Error('error')
}
});
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}
// findFirst query
const buyer = await this.prisma.buyer.findFirst({
where: {
id
},
rejectOnNotFound: true
});
1. so when I execute this findFirst
it does throw an error but not the error i defined in the prisma
config. Instead it says [NotFoundError: No Buyer found] { clientVersion: '2.26.0' }
2. Also, when I do NOT provide the rejectOnNotFound
in the findFirst
query it seems that the globally configured rejectOnNotFound
is not even doing anything...
3. as last, when I configure rejectOnNotFound
on a global level i'd expect that my buyer
variable can not be a possible null
value because it will be rejected if not found but it still says is possibly 'null'
Dev__
07/15/2021, 7:45 AMTomáš Kallup
07/15/2021, 7:53 AMrejectOnNotFound
).
I'm probably wrong to some extent thoRyan
07/15/2021, 10:09 AMDev__
07/15/2021, 10:59 AMRyan
07/15/2021, 11:01 AMTomáš Kallup
07/15/2021, 11:03 AMextends PrismaClient<LogOptions>
with extends PrismaClient<LogOptions & { rejectOnNotFound: true; }>
Tomáš Kallup
07/15/2021, 11:03 AMLogOptions
contains of course, you might need to override it.Dev__
07/15/2021, 11:08 AMDev__
07/15/2021, 11:09 AMTomáš Kallup
07/15/2021, 11:10 AMDev__
07/15/2021, 11:27 AMLogOptions
is an interfaceDev__
07/15/2021, 11:27 AMinterface LogOptions extends Prisma.PrismaClientOptions {
log: [
{
emit: 'event';
level: 'query';
}
];
}
Dev__
07/15/2021, 11:27 AMLogOptions & { rejectOnNotFound: true }
will not workTomáš Kallup
07/15/2021, 11:33 AMDev__
07/15/2021, 11:52 AMinterface LogOptions extends Prisma.PrismaClientOptions {
log: [
{
emit: 'event';
level: 'query';
}
];
}
@Injectable()
export class PrismaService
extends PrismaClient<LogOptions & { rejectOnNotFound: true }>
implements OnModuleInit, OnModuleDestroy
{
constructor() {
super({
log: [
{
emit: 'event',
level: 'query'
}
],
rejectOnNotFound: true
});
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}
Dev__
07/15/2021, 11:52 AMDev__
07/15/2021, 11:52 AM