Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Q: Is this todo app really works 'realtime'? #15

Open
rrjanbiah opened this issue Jul 11, 2019 · 1 comment
Open

Q: Is this todo app really works 'realtime'? #15

rrjanbiah opened this issue Jul 11, 2019 · 1 comment

Comments

@rrjanbiah
Copy link

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?

@lexi-lambda
Copy link

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:

const wsLink = new WebSocketLink(
new SubscriptionClient(REALTIME_GRAPHQL_URL, {
reconnect: true,
timeout: 30000,
connectionParams: {
headers: getHeaders(token)
}
})
);

…but it then chooses to only use that connection for subscription queries, so it uses the HTTP transport mechanism for other queries:

const link = split(
// split based on operation type
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === "OperationDefinition" && operation === "subscription";
},
wsLink,
httpLink
);

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.

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

2 participants