mst-gql icon indicating copy to clipboard operation
mst-gql copied to clipboard

How do I update data from server?

Open evansendra opened this issue 2 years ago • 1 comments

So far I've been able to query (once) and mutate data using mst-gql. In order to keep data fresh, in another project using apollo and a polling approach, I can do something like

useQuery<QueryResponseType>(QUERY, {
    variables,
    pollInterval: 1000,
    onCompleted(data) {
        state.updateData(data);
    },
    ...
}

which will automatically keep the state up to date with the server.

Is the equivalent of this in MST-GQL to setup a subscription using store.subscribeDataModel(...)? Or is there another way to setup polling so these changes are reflected in near real-time?

evansendra avatar Jul 24 '22 16:07 evansendra

Technically there's nothing stopping you from hand-writing a polling setup (e.g. use setInterval to repeatedly call the same query) but personally I use subscriptions as I believe polling to be wasteful. Either way, there's no need for a state.updateData because of Mobx's reactivity. Make sure your React components are setup properly to work with Mobx and everything should update automatically.

jesse-savary avatar Jul 25 '22 01:07 jesse-savary