Field middleware and plugins — GraphQL · NestJS

Code that runs around a single field and around a whole request: a field middleware that masks a microchip for anyone who is not staff, and an Apollo plugin, a Nest provider with its dependencies, that names every operation in a response header and a log.

What you will learn

Read the theory for Field middleware and plugins

All GraphQL lessons

All NestJS courses

loading types…

What you'll learn

  • Change a field's value on its way out with a FieldMiddleware attached through @Field({ middleware })
  • Read the request from a middleware's context, and know what field middleware cannot do (inject dependencies)
  • Hook into Apollo Server's request lifecycle with a @Plugin() class that implements ApolloServerPlugin
  • Register a plugin as a provider, so that it gets Nest's dependency injection, and set response headers from it