onCompleted callback is called when query skipped
Intended outcome:
When query defined in React functional component is skipped, onCompleted callback shouldn't be called
Actual outcome:
onCompleted callback is called with undefined as data
How to reproduce the issue:
I've created two sandboxes where issue is reproducible, first is based on @apollo/[email protected] where it seems to broke(works as expected in 3.1.4)
https://codesandbox.io/s/apollo-graphql-react-hooks-example-4v1z1
And second for latest @apollo/client based on error template
https://codesandbox.io/s/friendly-sun-fvgdp
In both cases to observe the issue you need to open console.
Version
System:
OS: macOS Mojave 10.14.6
Binaries:
Node: 12.12.0 - /var/folders/cj/b_yl586d1nz7rx814fny7qbw0000gq/T/fnm-shell-4163735/bin/node
Yarn: 1.19.1 - /usr/local/Cellar/yvm/3.6.7/shim/yarn
npm: 6.11.3 - /var/folders/cj/b_yl586d1nz7rx814fny7qbw0000gq/T/fnm-shell-4163735/bin/npm
Browsers:
Chrome: 80.0.3987.163
Firefox: 72.0.2
Safari: 13.1
I ran into this same issue. I reverted to 3.1.4, but still seem to have this problem.
same here
I ran into this when upgrading from 3.1.3
Same issue for me
same issue for me
I experienced this today and wasn't sure if it was intentional by design or not.
Same issue here. This is new behavior that only surfaced because we needed to introduce async code to ensure our token isn't expired for each call using apollo-link-conext. However, setting a breakpoint in the authLink's setContext callback, I find that it never gets called, but the query's onCompleted does. Very odd indeed. For now we just worked around this by exiting the onCompleted early if the skip condition is true:
const { loading, error } = useQuery(MY_QUERY, {
skip: isSkip,
fetchPolicy: 'network-only',
onCompleted: data => {
if (isSkip) return;
... code that should run when the query isn't skipped ...
}
});