prisma-nestjs-graphql icon indicating copy to clipboard operation
prisma-nestjs-graphql copied to clipboard

I want to use the generated dto's in my frontend as well, but the generated DTO models are not pure

Open TamirCode opened this issue 3 years ago • 3 comments
trafficstars

my backend generates the DTOs but I also want to make use of them in the frontend wherein i have forms that also use class-validator. However, the generated DTOs make use of things like @Field(() => companyWhereInput, {nullable:true}) which causes a lot of issues since it depends on @nestjs/graphql and if you install @nestjs/graphql on your frontend there is a ton of other unfixable errors. I want to generate DTOs that are compatible with my frontend and dont rely on a rabbit hole of nestjs graphql dependencies. For example, this: @Field(() => companyWhereInput, {nullable:true}) can be replaced with the class-validator equivalent: @IsOptional() However I am aware that @Field has other reasons for its existence and not just determining nullable true/false. So let me know your thoughts on this and possibly other solutions because I am not an expert in using this package, thank you

(my frontend uses Formik with class-validator-formik package)

TamirCode avatar Aug 07 '22 09:08 TamirCode

I think you need another generator, have you tried https://github.com/omar-dulaimi/prisma-class-validator-generator ?

unlight avatar Aug 07 '22 12:08 unlight

https://github.com/AnandChowdhary/prisma-class-validator https://github.com/botika/prisma-generator-nestjs-dto

unlight avatar Aug 07 '22 12:08 unlight

I have tried all of these and many others too, it seems I am out of luck. The last one you linked does plan on adding this in the future however. It would be cool if you would add an option in your generator to generate non-graphql dtos so they can be used easily in the frontend, though I understand if you wont because this whole package is based on graphql. But I still see a use for it regardless, since frontend can use same validators.

TamirCode avatar Aug 07 '22 13:08 TamirCode