onCompleted not called when useQuery refetch finished
Author: jthistleCreated Nov 23, 2019Updated Jul 19, 2020
Intended outcome:
Here is a brief, minimal outline of the inside of a React functional component I have:
const { refetch } = useQuery(MY_QUERY, {
variables: {
myVar
},
onCompleted: data => {
console.log('on completed');
sendAnEvent(false);
setSomeState(data.foo.bar);
},
});
function callback(event) {
console.log('callback');
refetch();
}
return (<div>
<button onClick={ () => callback() }>Click me</button>
</div>);What I expect is that, when I click the button:
- The message
callbackis output to the console - The query is executed
- The message
on completedis output to the console - All the other
onCompleteactions execute
Actual outcome:
- The message
callbackis output to the console - The query is executed
- The message
on completedis not output to the console and none of the otheronCompleteactions execute
How to reproduce the issue:
See this sandbox for a working minimal reproduction.
Version
@apollo/client: 3.0.0-beta4
Source: apollographql/react-apollo