Skip to content

Commit 77d2e95

Browse files
Update additional decorators docs to clarify applyResolversEnhanceMap 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>
1 parent 710adbb commit 77d2e95

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

docs/advanced/additional-decorators.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ sidebar_label: Applying decorators
77

88
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.
99

10-
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.:
10+
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.:
1111

1212
```ts
1313
import {
14+
resolvers,
1415
ResolversEnhanceMap,
1516
applyResolversEnhanceMap,
1617
} from "@generated/type-graphql";
@@ -23,6 +24,11 @@ const resolversEnhanceMap: ResolversEnhanceMap = {
2324
};
2425

2526
applyResolversEnhanceMap(resolversEnhanceMap);
27+
28+
const schema = await buildSchema({
29+
resolvers,
30+
validate: false,
31+
});
2632
```
2733

2834
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.

0 commit comments

Comments
 (0)