Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

useLazyQuery should only be called manually #3729

Open
minirom opened this issue Dec 5, 2019 · 2 comments
Open

useLazyQuery should only be called manually #3729

minirom opened this issue Dec 5, 2019 · 2 comments

Comments

@minirom
Copy link

minirom commented Dec 5, 2019

Intended outcome:

  • the lazy query should be executed only manually in a callback

Actual outcome:

  • if I never execute the lazy query and a render is called : the lazy query is not called (ok)
  • If I launch the lazy query manually, then update an input to re-render, the lazy query is launched (not ok)

How to reproduce the issue:

const controller = new AbortController();

  const [exportData] = useLazyQuery(query, {
    variables: {
      ...queryParameters,
      after: null,
      first: 10,
    },
    context: { fetchOptions: { signal: controller.signal } },
    fetchPolicy: 'network-only',
  });

// function called manually
  const onExport = useCallback(
    (extension) => {
      exportData();
    },
    [exportData]
  );

Version

System:
OS: Linux 4.15 Ubuntu 18.04.3 LTS (Bionic Beaver)
Binaries:
Node: 12.13.1 - /usr/bin/node
Yarn: 1.19.1 - /usr/bin/yarn
npm: 6.12.1 - /usr/bin/npm
Browsers:
Chrome: 78.0.3904.108
Firefox: 70.0.1

"@apollo/react-hooks": "^3.1.3",
"apollo-cache-inmemory": "^1.6.3",
"apollo-client": "^2.6.4",
"apollo-link": "^1.2.13",
"apollo-link-error": "^1.1.12",
"apollo-link-http": "^1.5.16",

@MarkPolivchuk
Copy link

I'm seeing the same behaviour. Between this and #3499 useLazyQuery feels like a trap.

@martdavidson
Copy link

Passing the variables into exportData({variables: {...}}) solved this for me, but it probably isn't expected behaviour.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants