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 #1246

Merged
merged 87 commits into from
Jan 10, 2022

Conversation

trevor-scheer
Copy link
Member

@trevor-scheer trevor-scheer commented Nov 25, 2021

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

@trevor-scheer trevor-scheer changed the base branch from version-0.x to release-gateway-0.45.0 November 25, 2021 16:58
@trevor-scheer trevor-scheer force-pushed the trevor/improve-supergraphSdl branch 2 times, most recently from c0afe14 to c705f2e Compare November 25, 2021 17:01
gateway-js/src/index.ts Outdated Show resolved Hide resolved
gateway-js/src/index.ts Outdated Show resolved Hide resolved
gateway-js/src/index.ts Outdated Show resolved Hide resolved
gateway-js/src/config.ts Show resolved Hide resolved
Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

oops didn't send this comment last week

gateway-js/src/legacy/serviceListShim.ts Outdated Show resolved Hide resolved
Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

Just a little skim to the stuff we talked about previously. Liking it overall!

gateway-js/src/index.ts Show resolved Hide resolved
gateway-js/src/index.ts Show resolved Hide resolved
gateway-js/src/index.ts Show resolved Hide resolved
gateway-js/src/supergraphManagers/LegacyFetcher/index.ts Outdated Show resolved Hide resolved
gateway-js/src/config.ts Outdated Show resolved Hide resolved
Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

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

If you agree with me and drop the duplicate calls to wrapSchemaWithAliasResolver (and the functions themselves) and look at the CHANGELOG tweaks below, then this looks good to me!

This is going to simultaneously enable folks to do more sophisticated things with schema loading and make understanding the state machine in index.ts much easier. Great work!

gateway-js/CHANGELOG.md Outdated Show resolved Hide resolved
gateway-js/CHANGELOG.md Outdated Show resolved Hide resolved
@trevor-scheer trevor-scheer changed the base branch from version-0.x to release-gateway-0.46.0 January 10, 2022 20:09
@trevor-scheer trevor-scheer merged commit 3270c51 into release-gateway-0.46.0 Jan 10, 2022
@trevor-scheer trevor-scheer deleted the trevor/improve-supergraphSdl branch January 10, 2022 20:15
trevor-scheer added a commit that referenced this pull request Jan 11, 2022
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/gateway runtime ↪️ port-to-2.x landed on 0.x but needs to be (forward) ported to 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants