Skip to content

Commit 2dd3e2a

Browse files
Merge branch 'tugascript-mercurius-plugins'
2 parents c740b3a + 6d15332 commit 2dd3e2a

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

content/graphql/plugins.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
### Plugins
2-
3-
> warning **Warning** This chapter applies only to the `@nestjs/apollo` driver.
1+
### Plugins with Apollo
42

53
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.
64

@@ -48,3 +46,31 @@ GraphQLModule.forRoot({
4846
```
4947

5048
> info **Hint** The `ApolloServerOperationRegistry` plugin is exported from the `@apollo/server-plugin-operation-registry` package.
49+
50+
#### Plugins with Mercurius
51+
52+
Some of the existing mercurius-specific Fastify plugins must be loaded after the mercurius plugin (read more [here](https://mercurius.dev/#/docs/plugins)) on the plugin tree.
53+
54+
> warning **Warning** [mercurius-upload](https://github.com/mercurius-js/mercurius-upload) is an exception and should be registered in the main file.
55+
56+
For this, `MercuriusDriver` exposes an optional `plugins` configuration option. It represents an array of objects that consist of two attributes: `plugin` and its `options`. Therefore, registering the [cache plugin](https://github.com/mercurius-js/cache) would look like this:
57+
58+
```typescript
59+
GraphQLModule.forRoot({
60+
driver: MercuriusDriver,
61+
// ...
62+
plugins: [
63+
{
64+
plugin: cache,
65+
options: {
66+
ttl: 10,
67+
policy: {
68+
Query: {
69+
add: true
70+
}
71+
}
72+
},
73+
}
74+
]
75+
}),
76+
```

0 commit comments

Comments
 (0)