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). For example, a basic logging plugin might log the GraphQL query string associated with each request that's sent to Apollo Server.
To create a plugin, declare a class annotated with the
@Plugin decorator exported from the
@nestjs/graphql package. Also, for better code autocompletion, implement the
ApolloServerPlugin interface from the
With this in place, we can register the
LoggingPlugin as a provider.
Nest will automatically instantiate a plugin and apply it to the Apollo Server.
Using external plugins
There are several plugins provided out-of-the-box. To use an existing plugin, simply import it and add it to the
info Hint The
ApolloServerOperationRegistryplugin is exported from the