router
router copied to clipboard
Add additional hooks for boot up and schema events
Is your feature request related to a problem? Please describe.
Today for the Rust plugins, rhai scripts, and coprocessor you can hook into the follow request lifecycle stages
- RouterService
- SupergraphService
- ExecutionService
- SubgraphService (called for every subgraph)
All of these stages are called on the way down processing the REQUEST as well as on the way back up processing the RESPONSE
To get access to other artifacts or change the Router behavior I have to use these lifecycle which all are hit for every single request so if I want information below I must serialize and send it as bytes on every request and keep track of the state myself too
- The supergraph version and SDL
- The current router config settings
- The operations and data in the cache
Describe the solution you'd like
It would be alot easier to keep track of the Router state if in the internal Router state machine we also called out to the customizations when there was an event
- RouterBootup
- SchemaFetch (http request out to GraphOS/Uplink)
- SupergraphLoad / Reload
- RouterShutdown
- PersistedQueryManifestLoad
- CacheAddition/Invalidation
- HTTPRequest (one truly in front of all internal router code for all incoming graph requests)
This would allow us to power more advanced usecases not only for the internal Router code base and our own product but also give customers and solutions teams access to build unique features that might not be for everyone.
- Save the supergraph SDL in Coprocessor to do custom validation and update on reload
- Pre-warm the query plan caches with my own custom list of operations
- Change the boot up configuration settings with data loaded from dynamic services
- Add custom logic if data should be cached or not
Describe alternatives you've considered
Even in Rust code itself, there is no external call during these events so we are forced to do all external processing on every request.
Also related is the behavior if a coprocessor fails: https://github.com/apollographql/router/issues/3271