Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update additional-decorators.md #425

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading