MichalLytek / MichalLytek/typegraphql-prisma

Add support for enhancing resolvers with decorators by CRUD scope

Open
#300 3 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

community enhancement priority:medium
Dominant language
TypeScript
Stars
918
Forks
130
PR merge metrics
No merged PRs in 30d

Description

> 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:
>
> ```ts
> const resolversEnhanceMap: ResolversEnhanceMap = {
> Event: {
> event: [Authorized()],
> events: [Authorized()],
> findFirstEvent: [Authorized()],
> aggregateEvent: [Authorized()],
> createEvent: [Authorized(Role.ADMIN)],
> createManyEvent: [Authorized(Role.ADMIN)],
> upsertEvent: [Authorized(Role.ADMIN)],
> updateEvent: [Authorized(Role.ADMIN)],
> updateManyEvent: [Authorized(Role.ADMIN)],
> deleteEvent: [Authorized(Role.ADMIN)],
> deleteManyEvent: [Authorized(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
> ```ts
> const resolversEnhanceMap: ResolversEnhanceMap = {
> Event: {
> _create: [Authorized(Role.ADMIN)]
> _read: [Authorized()],
> _update: [Authorized(Role.ADMIN)]
> _delete: [Authorized(Role.ADMIN)]
> },
> };
> ```
> or even
> ```ts
> const resolversEnhanceMap: ResolversEnhanceMap = {
> Event: {
> _mutate: [Authorized(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_

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ResolversEnhanceMap and the existing `_all` shorthand implementation, then trace how enhancement configuration reaches generated CRUD queries and mutations. Define the behavior of `_create`, `_read`, `_update`, `_delete`, `_mutate`, and `_query`, including their interaction with overrides, and verify it using an Event-style resolver enhancement map.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.