Files
main.tsmain
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
Press Run tests to start the app. Its log appears here.Graded endpoints
The field middleware lets the resolver produce the value, then masks all but the last three digits; null stays null
The middleware read the staff key from the request in its context, and passed the value through
The plugin names it anonymous, in the header as in the log
The plugin got OperationsLog by injection, like any provider, and recorded each response in order; this one is recorded after it is answered