Express-graphql: How to do live-reload

Created on 4 May 2017  路  10Comments  路  Source: graphql/express-graphql

I have a graphql based node application. I am using express-graphql.
How to enable live-reload. I want, whenever there is a change, graphiql should live-reload.
Edit: Read As
whenever there is a change in JavaScript files, graphiql should live-reload.

All 10 comments

is it possible to add something like

app.use('/graphql', graphqlHTTP({
  schema: MyGraphQLSchema,
  graphiql: true,
  livereload: true
}));

Assuming that when you say "whenever there is a change, graphiql should live-reload", you are referring to a change in the data on the server, no, that's not currently possible @nsisodiya, but it's a good question.

In terms of live updates:

  • Subscriptions are currently in RFC and soon to be added to the GraphQL spec (via this PR). See the original RFC PR and related issues for a bunch of discussion on that.
  • You'll see on those links a bunch of related discussion around a related concept which we're calling "live queries", but which are not yet in the spec nor do they exist as a formal RFC.
  • People have hacked together demos showing subscriptions working in GraphiQL: for example, see GraphiQL-Subscriptions-Fetcher. Apollo has also done work on making their graphql-server package support websockets. Likewise, @robzhu's React Conf talk shows a demo in GraphiQL, but note that this was bolted on for demonstration purposes around the time the RFC was being prepared, so it does not contain production ready or released code.

Whoops, didn't mean to hit close on that. Please feel free to comment further if you have any clarifications or questions.

What I mean to say, "when I make changes in File, graphiql tab should auto-reload".
I am NOT talking about reload when Data-Changes.

@wincent - Please re-open bug.

Can you clarify what kind of files you are making changes in? Do you mean files related to the schema (MyGraphQLSchema in your example)?

If so, check out this for one example of how this was done.

@wincent Basically, when JavaScript files changes, nodemon restart my node app. when this restart happen, I want a reload page/tab of graphiql.

@wincent I went to the link, That code, restart graphql server. I want, when server restart, client page (graphiql) should reload.

@nsisodiya reloading a client-side application (webpage in this case) when the server restarts sounds like a good "feature request" to me, but I'm not sure if we want to support it in this repo because:

  1. express-graphql's main purpose as I understand is to provide a thin easy-to-use endpoint in the format of express middleware, and in my personal opinion live-reloading constitutes as a nice-to-have feature rather than a must-have.
  2. There are some mini libraries that seem to already support your need. Take a look at this repo for instance - I pulled this from the quick Google search, so there might be a better alternative.

My recommendation to resolve your use case is to create a custom middleware in your server code, implement a live-reloading step in your custom middleware, and combine with this middleware to achieve your goal. In the future we may consider incorporating this option - we would love to consider and review any PRs should you choose to experiment with this idea and contribute.

Thanks for the question!

Was this page helpful?
0 / 5 - 0 ratings