Setting rejectOnNotFound globally doesn't provide type safety
See original GitHub issueBug description
Setting rejectOnNotFound
globally doesn’t change the typing of findUnique
or findFirst
const prisma = new PrismaClient({
rejectOnNotFound: true,
});
Then when I use findUnique
, It still returns Prisma.Prisma__UserClient<User | null>
instead of Prisma.Prisma__UserClient<User>
Expected behavior
It will be better if it’s typed. This might mean, generating types at runtime just like nexus
does. But a better approach will be to just include this property rejectOnNotFound
in the prisma schema itself within the generator block like this:
generator client {
provider = "prisma-client-js"
rejectOnNotFound = true
}
Environment & setup
- OS: Windows
- Database: PostgreSQL
- Node.js version: 14.16.1
- Prisma version:
2.21.2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Nextjs build: Property does not exist on type 'PrismaClient
I generated the migration file and ran the migrations in both local and production and verified the new table is present in both...
Read more >Prisma Client API (Reference)
If rejectOnNotFound is true, findUnique throws an error ( NotFoundError by default, customizable globally) instead of returning null . Reference. findUnique ...
Read more >nexus-prisma - npm
Type -safe Generated Library Code; Project Enums; Project Scalars ... For example if you set rejectOnNotFound globally on your Prisma Client ...
Read more >Features - Docs | Nexus Prisma - GitHub Pages
Prisma Client's rejectOnNotFound feature is effectively ignored by Nexus Prisma. For example if you set rejectOnNotFound globally on your Prisma Client it will ......
Read more >Prisma 4.0 Released: The Next Gen ORM - Morioh
We expect the new APIs to be easier to understand and more type-safe. ... statement:column "c" of relation "t1" does not exist Query:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ahmedosama7450 I don’t think we can have this option in the schema as people can do multiple instances of the client with different
rejectOnNotFound
option (eg. when sharing client in a monorepo) and the schema approach restricts that.I opened a documentation issue about the generic usage: https://github.com/prisma/docs/issues/1564#issuecomment-883668535
@toy-crane You need to do the following: