-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rejectOnNotFound throws Error when non-required relation is null #169
Comments
Please raise that issue on the Prisma side.
|
So I originally started a discussion on the Prisma repo, but the actual |
Sorry I miss-read, your comment. So the issue is on the Prisma side? Could you help me understand a little more what the actual problem is so I can open an issue with Prisma. |
You are resolving relations by using const user = await ctx.prisma.user.findUnique({
where: { id: args.where.id },
include: { Info: true },
});
return prisma.user.findUnique({
where: { id: parent.id },
}).posts(); So looks like your global |
Okay I understand now. So the Field Resolver that resolves the relation between the User and Info model needs some way of knowing not to throw an Error if it resolves too null. I'll open an issue over on Prisma. Cheers @MichalLytek 👋 |
Try running this one on your Prisma client: const prisma = new PrismaClient({
rejectOnNotFound: {
findUnique: {
User: (err) => new Error("Could not find user."),
},
},
});
// expect to throw error
await prisma.user.findUnique({
where: { id: "ckqjgja0b0009rxtp2b0avh92" },
rejectOnNotFound: true,
});
// expect to not throw anything
await prisma.user.findUnique({
where: { id: "ckqjgja0b0009rxtp2b0avh92" },
rejectOnNotFound: false,
});
// expect to not throw anything
await prisma.user.findUnique({
where: { id: "ckqjgja0b0009rxtp2b0avh92" },
}); |
Yeah so, 1 throws an Error, 2 doesn't, 3 does. It seems that if a relation resolves to Null when I call |
I could put |
I'll mention the issue here once I get it created, thanks for the help again. 👍 |
Raised; prisma/prisma#8929 |
Closing for a housekeeping purposes 🔒 The fix from Prisma will propagate to |
Describe the Bug
I'm attempting to throw an Error when findUnique() doesn't return a value for a given model. However when a relation on that model is null (it's not required) I'm getting an error back in
Errors
. My Prisma schema looks like:Prisma Client:
To Reproduce
I have a sample repo here: https://github.com/tnolan8/urql-prisma which has a Readme attached.
Expected Behavior
I would not expect there to be any Errors when a non-required relation is null when the Prisma Client is configured to only throw an Error when it's parent is null.
Logs
Here you can see that it returns the User correctly but also returns an Error.
Environment (please complete the following information):
typegraphql-prisma
version 0.14.8The text was updated successfully, but these errors were encountered: