Skip to Main Content
React Projects
book

React Projects

by Roy Derks
December 2019
Intermediate to advanced content levelIntermediate to advanced
474 pages
10h 3m
English
Packt Publishing
Content preview from React Projects

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React Projects - Second Edition

React Projects - Second Edition

Roy Derks
Test-Driven React

Test-Driven React

Trevor Burnham

Publisher Resources

ISBN: 9781789954937Supplemental Content