Retrieving near real-time data using GraphQL

Other than with the messaging application, you don't want the feed with posts to reload every time a new post has been posted by any of the people in your network. Besides subscriptions, there are other ways to have (near) real-time data flows with GraphQL and Apollo, namely, polling. With polling, you can retrieve a query from a useQuery Hook once every n milliseconds, saving you the complexity of setting up subscriptions.

Polling can be added to the useQuery Hook, like this one in client/Screens/Posts.js. By setting a pollInterval value on the object parameter from the useQuery Hook, you can specify how often the document with the GET_POSTS query should be resent by the Hook:

...const Posts ...

Get React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.