Open ketang opened 2 years ago
mark those fields as optional
I prefer the "mark those fields as optional" approach because I may want to correct or change a defaulted value (whether it is a timestamp or a default enum, etc).
Also, how should the Prisma "@updated" directive be handled? This is an implicit default.
I will look into the scenario generator as well as the SDL generator since it may try to assign values in its mocks.
I think it would be nice to use comment to inform generator what to skip. like what prisma-nestjs-graphql is doing.
Primsa schema
model Community {
id String @id @default(cuid())
/// @HideField({ input: true, output: false })
createdAt DateTime @default(now())
/// @HideField({ input: true, output: false })
updatedAt DateTime @updatedAt
/// @HideField({ match: 'CreateInput' })
isDeleted Boolean @default(false)
/// @HideField({ match: 'CreateInput' })
isActive Boolean @default(true)
title String
description String?
category CommunityCategory @relation(fields: [categoryId], references: [id])
categoryId Int
members CommunityMember[]
/// @HideField({ input: true, output: false })
createdBy User @relation("CommunityCreatedBy", fields: [createdById], references: [id])
/// @HideField({ input: true, output: false })
createdById String
/// @HideField({ input: true, output: false })
modifiedBy User @relation("CommunityModifiedBy", fields: [modifiedById], references: [id])
/// @HideField({ input: true, output: false })
modifiedById String
Event Event[]
location CommunityLocation?
}
You can see that I am defining which fields to be part of "input type" or "object type"
What's not working?
I have multiple model fields that have default values for ID generation, timestamps, etc., e.g.:
yarn rw sdl TestCase
generates the core type as expected:However the input type marks all defaulted fields as required (while recognizing the nullable field as optional):
What it should do instead is either mark those fields as optional
Or, as a lesser alternative, they could be omitted entirely from the input type:
How do we reproduce the bug?
Should produce output that includes:
What's your environment? (If it applies)
Are you interested in working on this?