-
Notifications
You must be signed in to change notification settings - Fork 118
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
Provide built-in helper to convert nulls to undefined from GraphQL args to Prisma Client #863
Comments
Hey, this feature would be very helpful! |
I think I am currently experiencing the described problem: t.list.field('AcademicYears', {
type: 'AcademicYear',
args: {
where: 'AcademicYearWhereInput',
first: intArg({ required: false }),
last: intArg({ required: false }),
},
resolve: async (root, { where }, ctx) => {
return ctx.prisma.academicYear.findMany({
where, // <-- error: Type 'null' is not assignable to type 'AcademicYearWhereInput | undefined'
})
},
}) Is there currently a workaround? |
Having the same issue here, too |
+1 |
They are rewriting the plugin from scratch #1039 |
+1 |
Yeah i ve got the exact same problem using a version of nexus-plugin-prisma and the last prisma3., Prisma do explain well the behavior between null and undefined In my side i decided to remove all field null, seems a better option than mutate to undefined because there is some difference of treatment for conditionals: i did create a empty function to remove any nulls from any field from the object coming from nexus
well if you don t want to work with typescript to help your code writing, just force any from the object and we do need anything else:
|
This is useful, however, how can this be done without losing type(s) checking in typescript ? |
Description
Historically,
null
was accepted for every Prisma Client args (pagination, filters etc..) because GraphQL does acceptnull | undefined
for nullable fields. Since a couple of versions, the Prisma Client removed the acceptance ofnull
for some of its args becausenull
has actual semantic value in some cases.When using Nexus, this can create some issues. Because nullable input object type fields are all typed as
null | undefined
, in some cases you might no longer be able to forward the args from your resolver down to the Prisma Client.Notes
Early proposals
Example:
The text was updated successfully, but these errors were encountered: