Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

How to do live-reload #296

Closed
nsisodiya opened this issue May 4, 2017 · 10 comments
Closed

How to do live-reload #296

nsisodiya opened this issue May 4, 2017 · 10 comments

Comments

@nsisodiya
Copy link

nsisodiya commented May 4, 2017

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.

@nsisodiya
Copy link
Author

is it possible to add something like

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

@wincent
Copy link
Contributor

wincent commented May 5, 2017

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.

@wincent wincent closed this as completed May 5, 2017
@wincent
Copy link
Contributor

wincent commented May 5, 2017

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

@nsisodiya
Copy link
Author

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.

@nsisodiya
Copy link
Author

@wincent - Please re-open bug.

@wincent
Copy link
Contributor

wincent commented May 5, 2017

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

@wincent
Copy link
Contributor

wincent commented May 5, 2017

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

@nsisodiya
Copy link
Author

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

@nsisodiya
Copy link
Author

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

@asiandrummer
Copy link
Contributor

@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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants