Skip to content

Commit

Permalink
Update additional decorators docs to clarify `applyResolversEnhanceMa…
Browse files Browse the repository at this point in the history
…p` usage

* Update additional-decorators.md

Hi, It took me a bit of time to use the method `applyResolversEnhanceMap`, I think this update could help people save time.

* Update additional-decorators.md

shorten the import

* Add explanation sentence

---------

Co-authored-by: Michał Lytek <michal.wojciech.lytek@gmail.com>
  • Loading branch information
vanduc1102 and MichalLytek authored Feb 7, 2024
1 parent 710adbb commit 77d2e95
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/advanced/additional-decorators.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ sidebar_label: Applying decorators

When you need to apply some decorators like `@Authorized`, `@UseMiddleware` or `@Extensions` on the generated resolvers methods, you don't need to modify the generated source files.

To support this, `typegraphql-prisma` generates two things: `applyResolversEnhanceMap` function and a `ResolversEnhanceMap` type. All you need to do is to create a config object, where you put the decorator functions (without `@`) in an array, and then call that function with that config, eg.:
To support this, `typegraphql-prisma` generates two things: `applyResolversEnhanceMap` function and a `ResolversEnhanceMap` type. All you need to do is to create a config object, where you put the decorator functions (without `@`) in an array, and then call that function with that config. Remember that it has to be done before building the schema, eg.:

```ts
import {
resolvers,
ResolversEnhanceMap,
applyResolversEnhanceMap,
} from "@generated/type-graphql";
Expand All @@ -23,6 +24,11 @@ const resolversEnhanceMap: ResolversEnhanceMap = {
};

applyResolversEnhanceMap(resolversEnhanceMap);

const schema = await buildSchema({
resolvers,
validate: false,
});
```

This way, when you call `createCategory` GraphQL mutation, it will trigger the `type-graphql` `authChecker` function, providing a `Role.ADMIN` role, just like you would put the `@Authorized` on top of the resolver method.
Expand Down

0 comments on commit 77d2e95

Please sign in to comment.