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

feat(gateway): Implement new supergraphSdl() config option for dynamic gateway updates (version 2 port) #1371

Merged
merged 4 commits into from
Jan 11, 2022

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Jan 11, 2022

This PR is duplicated (ported) to v2 from PR #1246. The description is directly copied from the original PR.


This PR originally introduced a new way to update the gateway dynamically via a supergraphSdl function. It's grown to substantially more than that (internally).

Firstly, this PR brings 2 new options for the supergraphSdl config. It can now be a SupergraphSdlHook or SupergraphManager. These new interfaces bring a much more "open" way to achieve gateway updates dynamically. These interfaces are probably best explained by their types (in config.ts) and usage examples in the docs. In short, the gateway now exposes a few handles to userland code via this option, which provide access to updating the supergraph, performing subgraph health checks, and accessing a subgraphs datasource.

Via some great comments from @glasser, this PR has also turned into a significant refactor (which fortunately tests and proves the flexibility of this interface). All means of updating the gateway now use the SupergraphManager interface under the hood. Ultimately, this should result in no change for existing use cases (minus one experimental hook removal, at the moment).

The gateway (instance itself) is no longer responsible for composition or polling. That responsibility now lives in various SupergraphManagers.

The following options are now deprecated, to be removed in a future version of gateway (and relatively soon) - all superseded by the capabilities of SupergraphManagers. Each of these options remain viable, but we urge you to move to supergraphSdl.

  • serviceList
  • localServiceList
  • experimental_updateSupergraphSdl
  • experimental_updateServiceDefinitions

The experimental_pollInterval option will also be deprecated (to be replaced by an equivalent pollIntervalInMs).

Fixes #1180

TODO

  • Docs
  • PR description
  • Changelog
  • Test serviceList and ServiceListShim equivalence?
  • Add additional deprecation warning for schemaConfigDeliveryEndpoint (unrelated but it should have one via 1283)
  • Deprecate experimental_pollInterval in favor of pollIntervalInMs

…mic gateway updates (#1246)

(copied from the changelog entry)

This change improves the `supergraphSdl` configuration option to provide a clean and flexible interface for updating gateway schema on load and at runtime. This PR brings a number of updates and deprecations to the gateway. Previous options for loading the gateway's supergraph (`serviceList`, `localServiceList`, `experimental_updateServiceDefinitions`, `experimental_supergraphSdl`) are all deprecated going forward. The migration paths all point to the updated `supergraphSdl` configuration option.

The most notable change here is the introduction of the concept of a `SupergraphManager` (one new possible type of `supergraphSdl`). This interface (when implemented) provides a means for userland code to update the gateway supergraph dynamically, perform subgraph healthchecks, and access subgraph datasources. All of the mentioned deprecated configurations now either use an implementation of a `SupergraphManager` internally or export one to be configured by the user (`IntrospectAndCompose` and `LocalCompose`).

For now: all of the mentioned deprecated configurations will still continue to work as expected. Their usage will come with deprecation warnings advising a switch to `supergraphSdl`.
* `serviceList` users should switch to the now-exported `IntrospectAndCompose` class.
* `localServiceList` users should switch to the similar `LocalCompose` class.
* `experimental_{updateServiceDefinitions|supergraphSdl}` users should migrate their implementation to a custom `SupergraphSdlHook` or `SupergraphManager`.

Since the gateway itself is no longer responsible for composition:
* `experimental_didUpdateComposition` has been renamed more appropriately to `experimental_didUpdateSupergraph` (no signature change)
* `experimental_compositionDidFail` hook is removed

`experimental_pollInterval` is deprecated and will issue a warning. Its renamed equivalent is `pollIntervalInMs`.

Some defensive code around gateway shutdown has been removed which was only relevant to users who are running the gateway within `ApolloServer` before v2.18. If you are still running one of these versions, server shutdown may not happen as smoothly.
@codesandbox-ci
Copy link

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.

@trevor-scheer
Copy link
Member Author

This was reviewed extensively and approved in #1246. I cherry picked the commit from that PR, addressed conflicts, and adjusted a few things as needed. I've given it a full pass as a sanity check. Given that CI is passing, I'm going to go ahead and land this. Happy to address any issues if they arise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(gateway): Replace serviceList API with more flexible, reactive option
1 participant