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

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

Open jasonmacdonald opened this issue 2 years ago • 5 comments

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?

jasonmacdonald avatar Nov 09 '22 14:11 jasonmacdonald

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

unlight avatar Nov 13 '22 08:11 unlight

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

jasonmacdonald avatar Nov 13 '22 14:11 jasonmacdonald

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

unlight avatar Nov 13 '22 14:11 unlight

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.

jasonmacdonald avatar Nov 13 '22 17:11 jasonmacdonald

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

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

mrBrownys avatar Apr 03 '24 10:04 mrBrownys