Graphql - Apollo Server - Hot update schema
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.