Q: Is this todo app really works 'realtime'?
rrjanbiah opened this issue · comments
As per the demo https://react-apollo-todo.demo.hasura.app it seems to make use of continuous 'polling' than 'WebSocket'. If so, what is the status of this app and what are the missing items that we need to consider before adopting it to other app?
If you take a look at react-apollo-todo/react-apollo/final-app/src/apollo.js
, you can see that it actually does open a WebSocket connection:
react-apollo-todo/react-apollo/final-app/src/apollo.js
Lines 40 to 48 in 914b6ad
…but it then chooses to only use that connection for subscription queries, so it uses the HTTP transport mechanism for other queries:
react-apollo-todo/react-apollo/final-app/src/apollo.js
Lines 51 to 59 in 914b6ad
The “polling” you’re seeing seems to be the mutation being made at regular intervals to update the current user’s “last online” time, which is using the HTTP transport mechanism. I’m not totally sure why it does that—there’s no reason it couldn’t be using the WebSocket mechanism for everything. That said, it would still have to send those mutations at regular intervals, since it’s pushing data from the client to the server, not polling the server for data. This application doesn’t do any polling to get new data from the server.
If you want to write your own application using Hasura, you can certainly use a WebSocket connection for all your queries if you want, and Hasura will push data to your client via the WebSocket for any subscription queries you make.