react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

onCompleted callback is called when query skipped

Open G07cha opened this issue 5 years ago • 7 comments

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

G07cha avatar Apr 21 '20 12:04 G07cha

I ran into this same issue. I reverted to 3.1.4, but still seem to have this problem.

KStone18 avatar Apr 28 '20 19:04 KStone18

same here

kissthom avatar Apr 29 '20 13:04 kissthom

I ran into this when upgrading from 3.1.3

mufasa3000 avatar Apr 29 '20 15:04 mufasa3000

Same issue for me

emiliachi avatar May 05 '20 16:05 emiliachi

same issue for me

joaohencke avatar May 28 '20 19:05 joaohencke

I experienced this today and wasn't sure if it was intentional by design or not.

Findiglay avatar Jun 04 '20 14:06 Findiglay

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 ...
  }
});

eberridge avatar Jun 10 '20 22:06 eberridge