-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve behavior of Disabled plugins #7104
Conversation
- Make it an error to install a built-in plugin and its "Disabled" counterpart in the same server. "Disabled" really means "don't install by default", but it's reasonable to assume it would counteract a manual installation of the same plugin too. For simplicity, this makes installing both flavors into an error at start time. This is technically backwards-incompatible but we are still early in the ASv4 lifecycle and this combination wasn't expected to have well-defined behavior. - Add `ApolloServerPluginSchemaReportingDisabled` which allows you to override the effect of the `APOLLO_SCHEMA_REPORTING` environment variable. - Doc improvements. Fixes #4778. Fixes #7099.
✅ Deploy Preview for apollo-server-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit e603b55:
|
docs/source/api/apollo-server.mdx
Outdated
You can _also_ add plugins to your server before you start it using the [`addPlugin`](#addplugin) method. | ||
|
||
Apollo Server comes with several plugins that it installs automatically in their default configuration if certain conditions are met. For example, the usage reporting plugin is installed if you provide a graph API key and a graph ref. Apollo Server skips this automatic installation if manually provide the plugin (in the `plugins` array or with the `addPlugin` method), or if you provide the plugin's corresponding "disabled" plugin (such as `ApolloServerPluginUsageReportingDisabled()` for `ApolloServerPluginUsageReporting`). For details, see the API references for these plugins: [usage reporting](./plugin/usage-reporting/), [schema reporting](./plugin/schema-reporting/), [landing page](./plugin/landing-pages/), [cache control](./plugin/cache-control/), and [inline trace](./plugin/inline-trace/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apollo Server comes with several plugins that it installs automatically in their default configuration if certain conditions are met. For example, the usage reporting plugin is installed if you provide a graph API key and a graph ref. Apollo Server skips this automatic installation if manually provide the plugin (in the `plugins` array or with the `addPlugin` method), or if you provide the plugin's corresponding "disabled" plugin (such as `ApolloServerPluginUsageReportingDisabled()` for `ApolloServerPluginUsageReporting`). For details, see the API references for these plugins: [usage reporting](./plugin/usage-reporting/), [schema reporting](./plugin/schema-reporting/), [landing page](./plugin/landing-pages/), [cache control](./plugin/cache-control/), and [inline trace](./plugin/inline-trace/). | |
Apollo Server comes with several plugins that it installs automatically in their default configuration if certain conditions are met. For example, the usage reporting plugin is installed if you provide a graph API key and a graph ref. Apollo Server skips this automatic installation if you manually provide the plugin (in the `plugins` array or with the `addPlugin` method), or if you provide the plugin's corresponding "disabled" plugin (such as `ApolloServerPluginUsageReportingDisabled()` for `ApolloServerPluginUsageReporting`). For details, see the API references for these plugins: [usage reporting](./plugin/usage-reporting/), [schema reporting](./plugin/schema-reporting/), [landing page](./plugin/landing-pages/), [cache control](./plugin/cache-control/), and [inline trace](./plugin/inline-trace/). |
packages/server/src/ApolloServer.ts
Outdated
for (const [ | ||
id, | ||
{ sawDisabled, sawNonDisabled }, | ||
] of pluginsByInternalID.entries()) { | ||
if (sawDisabled && sawNonDisabled) { | ||
throw new Error( | ||
`You have tried to install both ApolloServerPlugin${id} and ` + | ||
`ApolloServerPlugin${id}Disabled in your server. Please choose ` + | ||
`whether or not you want to disable the feature and install the ` + | ||
`appropriate plugin for your use case.`, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pro: this is verbose and it's easy to understand the logic here.
Con: we don't really need this loop, and could even cut the first one short and throw as soon as we see the true/true condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
@@ -12,6 +12,7 @@ export interface InternalApolloServerPlugin<TContext extends BaseContext> | |||
// Used to identify a few specific plugins that are instantiated | |||
// by default if not explicitly used or disabled. | |||
__internal_plugin_id__(): InternalPluginId; | |||
__is_disabled_plugin__(): boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbd, and this matches the existing pattern, but is it helpful that this is a function and not just a boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just assumed I had a reason for doing it this way before with the other one :) Will change both
f0e9a9c
to
e603b55
Compare
This PR was opened by the [Changesets release](/~https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @apollo/server-integration-testsuite@4.0.5 ### Patch Changes - Updated dependencies \[[`15d8d65e0`](15d8d65), [`e4e7738be`](e4e7738), [`e4e7738be`](e4e7738), [`15d8d65e0`](15d8d65)]: - @apollo/server@4.0.5 ## @apollo/server@4.0.5 ### Patch Changes - [#7104](#7104) [`15d8d65e0`](15d8d65) Thanks [@glasser](/~https://github.com/glasser)! - New `ApolloServerPluginSchemaReportingDisabled` plugin which can override the `APOLLO_SCHEMA_REPORTING` environment variable. - [#7101](#7101) [`e4e7738be`](e4e7738) Thanks [@glasser](/~https://github.com/glasser)! - Manage memory more efficiently in the usage reporting plugin by allowing large objects to be garbage collected more quickly. - [#7101](#7101) [`e4e7738be`](e4e7738) Thanks [@glasser](/~https://github.com/glasser)! - The usage reporting plugin now defaults to a 30 second timeout for each attempt to send reports to Apollo Server instead of no timeout; the timeout can be adjusted with the new `requestTimeoutMs` option to `ApolloServerPluginUsageReporting`. (Apollo's servers already enforced a 30 second timeout, so this is unlikely to break any existing use cases.) - [#7104](#7104) [`15d8d65e0`](15d8d65) Thanks [@glasser](/~https://github.com/glasser)! - It is now an error to combine a "disabled" plugin such as `ApolloServerPluginUsageReportingDisabled` with its enabled counterpart such as `ApolloServerPluginUsageReporting`. Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
ApolloServerPluginSchemaReportingDisabled
which allows you to override the effect of theAPOLLO_SCHEMA_REPORTING
environment variable.Fixes #4778. Fixes #7099.