Proper way to reload schema without restarting service?

Hi All!

Previously, I was using the apollo gateway load function to reload the schema (I don’t use the managed service), but since this commit and the introduction of phases it no longer works with the error being “Error: ApolloGateway.load called in surprising state loaded”. The function requires that the load functions is in the “initialized” state, which I’m not sure how to get to.

I was wondering if anyone had any suggestions of the correct way to do a manual reload of the schema. The idea is the I would like to expose an endpoint that would fetch the schemas whenever I hit it.

Can you provide a runnable example – at the very least sharing the code you’re using, but preferably either a small Git-clone-able repository or a Codesandbox example (here’s a decent starting app)?

Also, have you changed your underling Apollo Server to use await server.start()? Could you provide all the versions you’re using?

Hi Abernix!

I am using await server.start().
The verisons of depedency’s that I am trying to use are
@apollo/federation”: “^0.25.2”,
@apollo/gateway”: “^0.32.0”,
“apollo-server-express”: “^2.25.2”,

Please see the github repo here for a small runnable example. Using the “start-gateway” and “start-services” scripts. The /refreshSchema post call still has the same issue with this current version mentioned above. The last version that I noticed this working with was apollo gateway 0.22.0

Anyone have any suggestions on what is the recommended solution to reload the schema via some sort of exposed endpoint?

The Apollo-recommended solution is to use Managed federation. It’s free! Have you considered that?

Came here to say ^^. Managed Federation +1

1 Like

The suggestion to use managed federation is not a concrete solution. What if you can’t use Managed Federation because of internal company decisions? Are there any other solutions?

Yes there is, you write your own schema registry, modify the gateway to use your endpoint instead of what currently exists.

But before that, I think enterprise option might also have self-hosted option, check that if possible?

So in the newer versions of Apollo Federation (gateway, etc.) there is no way to tell the gateway to reload the schema other than Managed federation via Apollo Studio or restarting the gateway?

Unfortunately it kinda looks like that, please take my answer with a grain of salt, I don’t know much about this myself, last time I tried, I tried, managed federation looked like the only way, obviously there might be some experimental flag which I don’t know about, someone from apollo team might be able to answer this.

If the requirement to do is because of pricing options, I must say there’s no reason to worry about that though, apollo works really well without even paying, we’re paying because I like the schema checks from github.

If the requirement is because your company doesn’t allow usage of apollo studio, then I guess you might have to deploy gateway everytime a subgraph is updated. But that shouldn’t be a big deal though, right? we all do canary deployment, sure it’s annoying, but is that a deal breaker?

BTW, if you just sign up to apollo studio, the team is awesome that you’ll be able to setup a 15 mins call with them and you can just verbally put all your concerns and they’ll address them. I had an amazing experience with @GWashington

You can also try to look at type definitions to see if there’s any experimental flag which let’s you do the polling.

what if company dont accept to publish schemas in studio. how can we solve that ?

Instead of gateway.load(), has anyone tried either gateway.loadDynamic(false)? Might also be able to change the state before calling load() like this gateway.state = { phase: 'initialized' } (or maybe safer gateway.state.phase = 'initialized' which is the same state that Apollo Gateway sets. Of course, you run the risk of more state properties that might cause issues down the road with the second approach.