-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
InputType classes are needed for both: Create and Update of entity because of nullable. #424
Comments
How in that case make the argument optional (nullable) but not the fields itself? For the last few months I have a class operators in mind that works like the TS type operators (Parital, Required, Pick, Omit). But I have to check that and make a proof of concept first: @InputType()
export class TaskCreateInput implements Partial<Task> {
@Field()
name: string;
@Field()
numberOfPersonsNeeded: number;
@Field({ nullable: true })
description?: string;
@Field({ nullable: true })
location?: string;
}
@InputType()
export class TaskUpdateInput extends Partial(TaskCreateInput) {} |
I also ran into the same problem several times. It would be welcome feature for many of us. |
@MichalLytek I would absolutely love this feature. I use type-graphql with typeorm and it would save so much time to be able to generate gql types based on a typeorm entity. I've been trying to implement it myself but keep hitting walls and have to fall back to manually creating types and keeping them up to date when my entities change. Ideally I would love to be able to replicate some of the typegen stuff that prisma does for you, but without being locked into using their "orm"/database interface. It would also be nice to be able to map the keys of one type to new values in a new type. For example, I want to create an |
Closing in favor of #453 🔒 |
What is the best practice for this at the moment? I find myself in this exact situation with copy/pasted InputTypes where the update just adds |
@nickyhajal - Did you follow/ read the discussion in the issue Michal pointed to above? Scott |
Hey @smolinari, yep - it seems like @MichalLytek's last word on that thread is:
But, your comment made me revisit more closely and I do see the main recommendation was using a mixin as shown here: https://github.com/MichalLytek/type-graphql/tree/master/examples/mixin-classes What I'm not seeing in that example is how to make certain fields nullable in the UpdateInput, while required in the CreateInput. Is there something I'm missing here? Thanks! |
@nickyhajal |
Is your feature request related to a problem? Please describe.
When implementing the creation of an entity inside a resolver I find the need to create an InputType. This is perfectly fine. But I also want to implement the update for this entity, then I find myself duplicating the InputType and make some fields optional.
Describe the solution you'd like
Proposal/discussion: When adding the InputType using the Arg decorator, I add { nullable: true }. This would then make the fields within the InputType optional. This will however introduce a problem regarding nullable within the TypeScript InputType class.
I don't like the duplication just for the nullable fields (DRY).
Perhaps I'm just overlooking something..
Additional context
TaskCreate InputType
TaskUpdate InputType
The text was updated successfully, but these errors were encountered: