Company
Date Published
Author
David Glasser
Word count
619
Language
English
Hacker News points
None

Summary

The author of this article has implemented a dynamic GraphQL polling system with React and Apollo Client in Meteor Galaxy's admin interface. The goal is to show the state of internal database migrations, which requires adjusting the poll interval based on the data returned by the query. To achieve this, the author used the `options` parameter of the `graphql` function from react-apollo to set the poll interval dynamically, depending on the incoming props. They utilized the `withState` and `lifecycle` utilities from the reconcile library to implement this pattern, which involves passing down two props to a nested component: `pollInterval`, which defaults to a slow poll, and `setPollInterval`, which allows modifying it. The author checks the current value of `pollInterval` before changing it, ensuring that the state change is only applied when necessary. This implementation requires at least version 2.0.3 of Apollo Client.