refactor: Replace "cache-control" extension with plugin.#3997
Conversation
…o it. Similar to 6009d8a, which migrated the tracing package to the plugin API, this commit introduces a `plugin` (named) export from the `apollo-cache-control` module. It similarly accomplishes that by duplicating the behavior of the `CacheControlExtension` which leveraged the soon-to-be-deprecated `graphql-extensions`. The functionality, again, is intended to be identical in spirit. Since the delta of the commits was otherwise even _more_ confusing, I've left the `CacheControlExtension` present and exported and will remove it in a subsequent commit. Briefly summarizing what the necessary changes were: 1. We no longer use a class instance to house the extension, which was necessitated by the `graphql-extensions` API. This means that uses of `this` have been replaced with function scoped variables by the same name. 2. The logic which actually does the formatting (previously handled by the `format` method in `graphql-extension`, now takes place within the plugin API's `willSendResponse` method. 3. Rather than leaning on plugin-specific behavior from within the request pipeline, the `apollo-cache-control` plugin now makes a number of assertions throughout its various life-cycle methods to ensure that the `overallCachePolicy` is calculated. 4. Switch tests to use the new `pluginTestHarness` method for testing plugins which was introduced in eec87a6 (#3990).
Which has been replaced by the plugin API introduced in 68cbc93.
…ns". Similar to 6009d8a (#3991) and 68cbc93 (#3997), which migrated the tracing and cache-control extensions to the (newer) request pipeline plugin API, this commit introduces: - Internally, a `plugin` named export which is utilized by the `agent`'s `newExtension` method to provide a plugin which is instrumented to transmit metrics to Apollo Graph Manager. This plugin is meant to replicate the behavior of the `EngineReportingExtension` class which, as of this commit, still lives besides it. - Externally, a `federatedPlugin` exported on the main module of the `apollo-engine-reporting` package. This plugin is meant to replicate the behavior of the `EngineFederatedTracingExtension` class (also exported on the main module) which, again as of this commit, still lives besides it! Again, the delta of the commits seemed more confusing by allowing a natural `diff` to be made of it, I've left the extensions in place so they can be compared - presumably side-by-side in an editor - on the same commit. An (immediate) subsequent commit will remove the extension.
| // A follow-up commit will actually introduce this. | ||
|
|
||
| // Enable cache control unless it was explicitly disabled. | ||
| if (this.config.cacheControl !== false) { |
There was a problem hiding this comment.
With cacheControl implemented as a plugin now, do you anticipate we'll remove this configuration point in a future major (v4)?
There was a problem hiding this comment.
Possibly. I feel like our cacheControl integration might get tighter over time, but it's certainly possible we could have configuration be entirely composable via plugins. I don't imagine we'd sacrifice this particular convenience plugin initialization anytime soon though.
…abernix/migrate-cache-control-to-plugin-api
…abernix/migrate-cache-control-to-plugin-api
…abernix/migrate-cache-control-to-plugin-api
…abernix/migrate-cache-control-to-plugin-api
…rate-cache-control-to-plugin-api
…rate-cache-control-to-plugin-api
| }, | ||
| }), | ||
|
|
||
| responseForOperation() { |
There was a problem hiding this comment.
@abernix Do you have any memory of why this is here? This runs before execution, so I don't see how the policy it calculates could ever be non-trivial. I don't see anything that obviously matches it on the "before" side of this PR. Tests pass without it (on my PR that refactors some stuff).
Similar to 6009d8a (#3991), which migrated the tracing package to the plugin API, this commit introduces a
plugin(named) export from theapollo-cache-controlmodule. It similarly accomplishes that by duplicating the behavior of theCacheControlExtensionwhich leveraged the soon-to-be-deprecatedgraphql-extensions. The functionality, again, is intended to be identical in spirit.As with the afformentioned commit, since the delta of the commits was otherwise even more confusing, I've left the
CacheControlExtensionpresent and exported and will remove it in a subsequent commit.Briefly summarizing what the necessary changes were:
graphql-extensionsAPI. This means that uses ofthishave been replaced with function scoped variables by the same name.formatmethod ingraphql-extension, now takes place within the plugin API'swillSendResponsemethod.apollo-cache-controlplugin now makes a number of assertions throughout its various life-cycle methods to ensure that theoverallCachePolicyis calculated.pluginTestHarnessmethod for testing plugins which was introduced in eec87a6 (Introduce an internal plugin test harness to facilitate plugin testing. #3990).