unlight / prisma-nestjs-graphql

Generate object types, inputs, args, etc. from prisma schema file for usage with @nestjs/graphql module
MIT License
540 stars 79 forks source link

[Question] Adding a decorator to all INPUT classes for a given model #143

Open jasonmacdonald opened 2 years ago

jasonmacdonald commented 2 years ago

I'm trying to figure out if it's possible to add a decorator to all @InputType classes instead of just on the @ObjectType. The reason being is that I'm trying to add role permission checking, and it would be nice to do that on the InputType, but thus far, I haven't found the right combination to do that. Is it not possible? Can we only validate/decorate fields on @InputTypes?

unlight commented 2 years ago

There is a way to add any decorator to any generated class https://github.com/unlight/prisma-nestjs-graphql#decorate

jasonmacdonald commented 2 years ago

As far as I can tell, this only adds it to the ObjectType, not the InputTypes. :(

unlight commented 2 years ago

This test is adding decorator for ProfileUncheckedCreateNestedOneWithoutUserInput which is @InputType decorated

jasonmacdonald commented 2 years ago

Ah, I see, you aren't using an annotation in the Prisma file. I don't really want to have to call out every single input on every model like that if I can avoid it. I was using...

/// @Directive({ arguments: ['@Authz(roles:{create: ["ADMIN"], update:["ADMIN","OWNER"]})']})
model User {
...
}

And this only added the Directive to the ObjectType. :( I was trying to Decorate the Input classes, not the properties.

mrBrownys commented 7 months ago

@unlight any updates? no way to decorate InputType or ObjectType class, like this?

@ObjectType() @Extensions({ is: true }) export class AggregateGame {