Skip to content
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

Merged
merged 2 commits into from
Oct 31, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Oct 31, 2022

  • 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.

- 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.
@netlify
Copy link

netlify bot commented Oct 31, 2022

Deploy Preview for apollo-server-docs ready!

Name Link
🔨 Latest commit e603b55
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/636033b102797c000864190b
😎 Deploy Preview https://deploy-preview-7104--apollo-server-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@glasser glasser requested review from rkoron007 and trevor-scheer and removed request for trevor-scheer October 31, 2022 19:45
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 31, 2022

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:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

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/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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/).

Comment on lines 839 to 851
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.`,
);
}
}
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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?

Copy link
Member Author

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

@glasser glasser enabled auto-merge (squash) October 31, 2022 20:32
@glasser glasser force-pushed the glasser/disabled-plugin-improvements branch from f0e9a9c to e603b55 Compare October 31, 2022 20:44
@glasser glasser merged commit 15d8d65 into main Oct 31, 2022
@glasser glasser deleted the glasser/disabled-plugin-improvements branch October 31, 2022 20:47
@github-actions github-actions bot mentioned this pull request Oct 31, 2022
glasser pushed a commit that referenced this pull request Oct 31, 2022
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>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants