You can use express to refresh your gateway's schema. ApolloGateway has a load()
function that go out to fetch the schemas from implementing services. This HTTP call could potentially be part of a deployment process if something automatic is needed. I wouldn't go with polling or something too automatic. Once the implementing services are deployed, the schema is not going to change until it's updated and deployed again.
import { ApolloGateway } from '@apollo/gateway';
import { ApolloServer } from 'apollo-server-express';
import express from 'express';
const gateway = new ApolloGateway({ ...config });
const server = new ApolloServer({ gateway, subscriptions: false });
const app = express();
app.post('/refreshGateway', (request, response) => {
gateway.load();
response.sendStatus(200);
});
server.applyMiddleware({ app, path: '/' });
app.listen();
Update: The load()
function now checks for the phase === 'initialized'
before reloading the schema. A work around might be to use gateway.loadDynamic(false)
or possibly change gateway.state.phase = 'initialized';
. I'd recommend loadDyamic()
because change state might cause issues down the road. I have not tested either of those solutions since I'm not working with Apollo Federation at the time of this update.