Closed robnewton closed 3 years ago
Hi @robnewton, to subscribe to the offline store I suggest you read my answer in another similar issue: https://github.com/morrys/wora/issues/57#issuecomment-651324974
While for the connectivity problem I suppose this is a known problem of the netinfo library: https://github.com/react-native-netinfo/react-native-netinfo#issues-with-the-ios-simulator
Thanks for the quick response. We will take a look at those two things.
@morrys I wonder how the mutation is being cached correctly if the simulator is improperly reporting online. Does ApolloOffline have an internal check that is more robust that could cause the isOnline() function to return true but still know to queue the mutation inside?
@morrys onPublish() which is recommended by you in the other issue to get queued mutation alerts is not being called when a mutation is added to the queue for us. We never see that function get called at all despite the offline mutation actually works. Could this be related to the iOS simulator failing to show the online state correctly?
@morrys We just tried the following expecting a console log of the subscription call but we never get anything in the console.
useEffect(() => {
const dispose = client.getStoreOffline().subscribe((state, action) => {
console.log('Offline mutation added: ', state, action);
setOfflineMutationCount(state.length);
});
return () => {
dispose(); // Make sure we unsubscribe when we're unmounted
};
}, []);
If the onPublish function is not called it means that the mutation is not performed in offline mode but online. This problem is due to the iOS simulator
Ok that makes sense, thank you @morrys for the help
@morrys In our first attempts to use ApolloOffline we are simply trying to understand the correct usage with some simple boiler plate to show connection status and whether there are any mutations currently in the queue. Our code below is our attempt to do this but while it seems to be functioning, the status information doesn't appear correct and the callback event functions aren't called when the mutations finally do execute.
Any advice on how we can get some of these things working would be appreciated. If you have a more complete React Native example with this type of basic implementation you can point us at too, that would be helpful I think.
Our test consists of a couple on screen buttons:
checkMorrys()
function to write to the console the result of getState() and getListMutation() then set connection status into React State to show on screen whether it thinks we are online or not.Here's our test steps:
storeOffline.getState()
andstoreOffline.getListMutation()
get written to the console as empty for both (but we expected to see the one mutation in the offline mutation queue here)onExecute()
function get called but it does notOur app.js...