-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
[Prisma plugin] Non-nullable type should not be allowed with one-to-one relation #957
Comments
This is an odd edge case, and I've had users with strong opinions on both sides. While technically I think this would be more correct, and Pothos generally tries to be as type-safe and strict as possible, there are also users who have nullable relations in their schemas they know will always be set and want to expose as non-null. I've gone back and forth on the correct thing to do here a few times. Taking a step back, another principle in Pothos (which the prisma plugin does violate in a few ways) is that it should ultimately always be the Pothos code, not the underlying datasources that determine the shape of a schema. Generally speaking the schema should never change without changing pothos code. This is why the nullability of a relation shouldn't change the nullability of a field. On the other hand, having a type-error when the underlying data does not match the schema you are defining is what most closely aligns with pothos principles. In pothos the default is to be non-nullable, which makes I agree that this should result in an Error, but the implementation needs to account for a few things:
I'm open to suggestions/PRs on how to handle this, unfortunately, I don't think something as simple as just making |
I understand that there are indeed users who have nullable relations in their schemas that they know will always be set and want to expose as non-null.
I see. I come up with options like below:
postDetail: t.relation('postDetail', { nullable: false, resolveNull: () => {
throw new Error('Message!')
} })
postDetail: t.relation('postDetail', { forceNonNullable: true }) But, the implementation may cause error messages with difficulty in understanding. |
this may be a good candidate for #279, I have been working on v4 for a while, there are a couple open questions I need to resolve to actually get it released, but this issue feels like a good thing to add there |
There is a bug when 1 to 1 relation is used in Prisma schema.
Example schema file:
Example output:
is allowed but
nullable: false
should not allowed here because the prisma client could return null for the relationpostDetail
.The text was updated successfully, but these errors were encountered: