You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/directives.md
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,10 +86,31 @@ Besides declaring the usage of directives, you also have to register the runtime
86
86
87
87
> Be aware that TypeGraphQL doesn't have any special way for implementing schema directives. You should use some [3rd party libraries](https://the-guild.dev/graphql/tools/docs/schema-directives#implementing-schema-directives) depending on the tool set you use in your project, e.g. `@graphql-tools/*` or `ApolloServer`.
88
88
89
+
If you write your custom GraphQL directive or import a package that exports a `GraphQLDirective` instance, you need to register the directives definitions in the `buildSchema` options:
90
+
91
+
```ts
92
+
// Build TypeGraphQL executable schema
93
+
const tempSchema =awaitbuildSchema({
94
+
resolvers: [SampleResolver],
95
+
// Register the directives definitions
96
+
directives: [myDirective],
97
+
});
98
+
```
99
+
100
+
Then you need to apply the schema transformer for your directive, that implements the desired logic of your directive:
101
+
102
+
```ts
103
+
// Transform and obtain the final schema
104
+
const schema =myDirectiveTransformer(tempSchema);
105
+
```
106
+
107
+
If the directive package used by you exports a string-based `typeDefs`, you need to add those typedefs to the schema and then apply directive transformer.
108
+
89
109
Here is an example using the [`@graphql-tools/*`](https://the-guild.dev/graphql/tools):
0 commit comments