This seems similar to https://github.com/apollostack/react-apollo/issues/358 (but possibly unrelated).
Here is my situation:
But, if I click the button again, this happens:
I've isolated this in a reproduction case:
git clone https://github.com/jbinto/apollo_polling_bug/
cd apollo_polling_bug
yarn
npm start
To keep things simple I don't do a mutation, just controlling props with setTimeout is sufficient to reproduce. I used a mock network interface that just echoes back an argument.
Relevant files:
https://github.com/jbinto/apollo_polling_bug/blob/master/src/index.js
https://github.com/jbinto/apollo_polling_bug/blob/master/src/Foo.js
Somehow, apollo-client or react-apollo is holding on to old variables and issuing queries based on those, despite the fact the props of the graphql HOC have changed.
I should be able to combine skip, forceFetch, and pollInterval as such:
forceFetch and pollInterval are fixed as true, and 1000 respectively. skip begins as true.skip to false, by re-rendering with new props (including an id prop, which is used in options.variables)skip to true, polling stopsskip to false, and send a new id propid prop I provided to options.variables, not the old oneThank you @jbinto for the excellent reproduction.
Can confirm the problem and also that it's not AC (see this branch: https://github.com/tmeasday/apollo_polling_bug/tree/pure-apollo-client)
Ok, so I think the issue is here: https://github.com/apollostack/react-apollo/blob/master/src/graphql.tsx#L343-L345
It assumes that we've either (a) just created the query with the current options and need to create a subscription or (b) we may be changing the options and the subscription should exist.
This is obviously third case that needs to be dealt with.
Started working on a solution, hit a couple of snags, will try and resolve the snags soon unless someone else solves them for me: https://github.com/apollostack/react-apollo/pull/376
(Also this is quite annoying: https://github.com/apollostack/react-apollo/issues/375)
Thanks for the quick turnaround!