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.
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:
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:
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.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!