I am looking to hot reload my GraphQL schema on my apollo-server-express server. Anyone would have any idea about how to do that?
I'm currently using schemas stitching to gather multiple API's schemas, however I do not want to have to restart my application every time one of these schema changes.
I've tried to look for the express route and remove it but that dit not work, I also tried to call graphQLExpress()
again on the same route and that did not update it.
Thanks for your help!
I dug into the graphqlExpress
call a bit, it's fairly lightweight and just returns a middleware function using the provided schema. I was able to ensure it's always using my latest schema by wrapping it:
let schema = createSchema();
app.use('/graphql', bodyParser.json(), function(req, res, next) {
// ensure latest schema is always passed in, we'll reload it automatically
const graphql = graphqlExpress({ schema });
graphql(req, res, next);
});
I'm working with local / static schema at the moment, so a file watcher allows me to update schema
here as needed.
I managed to get it done by removing the express route and then re-creating it. But actually I discovered that because makeRemoteExecutableSchema
is sending the introspection query at every request, you actually don't need to update your schema, it gets updated by itself. That does not imply Graphiql though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With