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: content/graphql/directives.md
+33-22Lines changed: 33 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,38 +10,49 @@ A directive is an identifier preceded by a `@` character, optionally followed by
10
10
11
11
#### Custom directives
12
12
13
-
To create a custom schema directive, declare a class which extends the `SchemaDirectiveVisitor` class exported from the `@graphql-tools/utils` package.
13
+
To instruct what should happen when Apollo/Mercurius encounters your directive, you can create a transformer function. This function uses the `mapSchema` function to iterate through locations in your schema (field definitions, type definitions, etc.) and perform corresponding transformations.
const result =awaitresolve(source, args, context, info);
38
+
if (typeofresult==='string') {
39
+
returnresult.toUpperCase();
40
+
}
41
+
returnresult;
42
+
};
43
+
returnfieldConfig;
26
44
}
27
-
returnresult;
28
-
};
29
-
}
45
+
},
46
+
});
30
47
}
31
48
```
32
49
33
-
> info **Hint** Note that directives cannot be decorated with the `@Injectable()` decorator. Thus, they are not able to inject dependencies.
34
-
35
-
> warning **Warning**`SchemaDirectiveVisitor` is exported from the `@graphql-tools/utils` package. Note that the 8.x release of `graphql-tools` removes this export and provides a different and incompatible approach to directives, so make sure to install `@graphql-tools/utils@^7` in your project.
36
-
37
-
Now, register the `UpperCaseDirective` in the `GraphQLModule.forRoot()` method:
50
+
Now, apply the `upperDirectiveTransformer` transformation function in the `GraphQLModule#forRoot` method using the `transformSchema` function:
0 commit comments