typegraphql-prisma
typegraphql-prisma copied to clipboard
Add support for enhancing resolvers with decorators by CRUD scope
I am currently working on a project, using TypeGraphQL-Prisma, where I often encounter the case of 'any authenticated user can Read objects, but only admins can Create, Update, or Delete'.
as such my enhance maps look like this:
const resolversEnhanceMap: ResolversEnhanceMap = { Event: { event: [Authorized()], events: [Authorized()], findFirstEvent: [Authorized()], aggregateEvent: [Authorized()], createEvent: [Authorized<Role>(Role.ADMIN)], createManyEvent: [Authorized<Role>(Role.ADMIN)], upsertEvent: [Authorized<Role>(Role.ADMIN)], updateEvent: [Authorized<Role>(Role.ADMIN)], updateManyEvent: [Authorized<Role>(Role.ADMIN)], deleteEvent: [Authorized<Role>(Role.ADMIN)], deleteManyEvent: [Authorized<Role>(Role.ADMIN)], }, };
Might it be benificial to implement, in addition to the
_all
shorthand, shorthands like_create
,_update
,_read
, and_delete
?
It seems like this could already greatly reduce the amount of code needed to specify separate config for queries and mutations that belong together.something like
const resolversEnhanceMap: ResolversEnhanceMap = { Event: { _create: [Authorized<Role>(Role.ADMIN)] _read: [Authorized()], _update: [Authorized<Role>(Role.ADMIN)] _delete: [Authorized<Role>(Role.ADMIN)] }, };
or even
const resolversEnhanceMap: ResolversEnhanceMap = { Event: { _mutate: [Authorized<Role>(Role.ADMIN)] _query: [Authorized()], }, };
This could still work in conjunction with the proposed overrides, if needed.
Originally posted by @MitchJans in https://github.com/MichalLytek/typegraphql-prisma/issues/136#issuecomment-1164228825
I have the very exact use case and would love to see this implemented.
This would be amazing!
I am also interested in this feature, it will make things easier for scoped authorisations!