Skip to content

Commit 46e9699

Browse files
Merge branch 'mercurius-plugins' of https://github.com/tugascript/docs.nestjs.com into tugascript-mercurius-plugins
2 parents c740b3a + 84623da commit 46e9699

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

content/graphql/plugins.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Plugins
22

3-
> warning **Warning** This chapter applies only to the `@nestjs/apollo` driver.
3+
#### For `@nestjs/apollo` driver
44

55
Plugins enable you to extend Apollo Server's core functionality by performing custom operations in response to certain events. Currently, these events correspond to individual phases of the GraphQL request lifecycle, and to the startup of Apollo Server itself (read more [here](https://www.apollographql.com/docs/apollo-server/integrations/plugins/)). For example, a basic logging plugin might log the GraphQL query string associated with each request that's sent to Apollo Server.
66

@@ -48,3 +48,31 @@ GraphQLModule.forRoot({
4848
```
4949

5050
> info **Hint** The `ApolloServerOperationRegistry` plugin is exported from the `@apollo/server-plugin-operation-registry` package.
51+
52+
#### For `@nestjs/mercurius` driver
53+
54+
Some mercurius specific fastify plugins have to be loaded after the mercurius plugin (read more [here](https://mercurius.dev/#/docs/plugins)) on the plugin tree.
55+
56+
> warning **Warning** [mercurius-upload](https://github.com/mercurius-js/mercurius-upload) is an exception and should be registered in the main file.
57+
58+
There is an optional `plugins` array parameter inside the `MercuriusDriver`, this array takes an object with the plugin function on the `plugin` parameter and its options inside an optional `options` parameter. Therefore, registering the [cache plugin](https://github.com/mercurius-js/cache) would be as follows:
59+
60+
```typescript
61+
GraphQLModule.forRoot({
62+
driver: MercuriusDriver,
63+
// ...
64+
plugins: [
65+
{
66+
plugin: cache,
67+
options: {
68+
ttl: 10,
69+
policy: {
70+
Query: {
71+
add: true
72+
}
73+
}
74+
},
75+
}
76+
]
77+
}),
78+
```

0 commit comments

Comments
 (0)