typegraphql-prisma
typegraphql-prisma copied to clipboard
Allow configuring nullability
Is your feature request related to a problem? Please describe.
Take the following schema
model User {
id Int @id @default(autoincrement())
email String
firstName String
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
message String
author User @relation(fields: [authorId], references: [id])
authorId Int
}
I'd like to create a middleware or decorator that automatically connects currentUser (from context) to the author field of Post in the CreatePostResolver. For example
export const ConnectCurrentUser: MiddlewareFn<Context> = async ({ context }, next) => {
if (!context.currentUser) {
throw new ValidationError()
}
return {
connect: {
id: context.currentUser.id,
} as UserWhereUniqueInput,
}
}
applyInputTypesEnhanceMap({
PostCreateInput: {
fields: {
author: [UseMiddleware(ConnectCurrentUser)],
},
},
})
This would work fine, however nullable: false on the author field prevents the mutation from working without any input for the field.
Describe the solution you'd like I'd love a way to configure nullability on a per-field basis.
Any news about this feature?