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

Unable to call ApolloGateway.load() running version > 22 #61

Open
brettski opened this issue Mar 4, 2021 · 1 comment
Open

Unable to call ApolloGateway.load() running version > 22 #61

brettski opened this issue Mar 4, 2021 · 1 comment
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@brettski
Copy link
Collaborator

brettski commented Mar 4, 2021

Calling ApolloGateway.load() throws the error Error: ApolloGateway.load called in surprising state loaded
We call this at,

const { schema, executor } = await graphServer.config.gateway.load();

The issue is due to an update made to Apollo Gateway in version 0.23.0 noted in their changelog

If you are on v2.18 or v2.19 of Apollo Server, you should upgrade to Apollo Server v2.20 before upgrading to this version, or your Node process may not shut down properly after stopping your Apollo Server.. Code that calls ApolloGateway.load is now expected to call ApolloGateway.stop. If you don't do that and you're using managed federation or experimental_pollInterval, the background polling interval will now keep a Node process alive rather than allowing it to exit if it's the only remaining event loop handler. Generally, ApolloServer is what calls ApolloGateway.load, and if you use at least v2.20.0 of Apollo Server, ApolloServer.stop() will invoke ApolloGateway.stop(). There's a bit of a hack where ApolloGateway does the old behavior if it believes that it is being called by a version of Apollo Server older than v2.18.0. So if you are manually calling ApolloGateway.load from your code, make sure to call ApolloGateway.stop when you're done, and don't use this version with Apollo Server v2.18 or v2.19. PR #452 apollo-server Issue #4428

I tried adding a gateway.stop() before, after, and other places but that didn't help this issue. I am not sure what it is looking for here or how to resolve this surprising state.

@apollo/gateway version currently locked at "0.22.0"

NOTE

A very strange aspect of this is that currently in production the package.json file has @apollo/gateway 0.23.0 listed and the refresh request works as expected. Locally, this isn't the case, even using that same version.

Looking at @apollo/gateway source, I don't see how we can get the correct state of initialized when calling load(). It seems we need to rethink the approach we are using to update the gateway when children are reloaded/deployed/etc.

https://github.com/apollographql/federation/blob/e3b3035711d31f60a053ceafa3828666fe808435/gateway-js/src/index.ts#L266-L274

  public async load(options?: {
    apollo?: ApolloConfig;
    engine?: GraphQLServiceEngineConfig;
  }) {
    if (this.state.phase !== 'initialized') {
      throw Error(
        `ApolloGateway.load called in surprising state ${this.state.phase}`,
      );
    }
....

Came across this issue in the Apollo Federation repo: apollographql/federation#461
It describes another user losing their ability to run ApolloGateway.load() to refresh schemas.

@brettski brettski added bug Something isn't working help wanted Extra attention is needed labels Mar 4, 2021
@brettski brettski self-assigned this Mar 4, 2021
@brettski
Copy link
Collaborator Author

brettski commented Mar 5, 2021

Came across this issue in the Apollo Federation repo: apollographql/federation#461
It describes another user losing their ability to run ApolloGateway.load() to refresh schemas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants