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

useLazyQuery with the same document as useQuery triggers onCompleted for the latter

Open jbaccarelli-equinix opened this issue 3 years ago • 2 comments

A simple question i think, i don't know if this is on purpose.

I have a table, for which I use useQuery to get it's data, paginated, on load, but then I have a button in a menu, where I want to fetch all the available records from the backend to print to CSV, the problem is that when I execute the useLazyQuery (using the same document but with more records requested) the call is fine, but the onCompleted of the original useQuery is executed too, I can't find a way to prevent this from happening, maybe if I had some flag I can use there to say "don't do what it's in here since the call was from another hook"?

Any ideas?

jbaccarelli-equinix avatar Aug 18 '22 13:08 jbaccarelli-equinix

+1

Also if I use two useLazyQuery on the same app page I get infinite loop. Response from the second useLazyQuery triggers the first useLazyQuery and the first useLazyQuery triggers the second useLazyQuery and so on. I believe this case is probably related to situation above.

RustamKarimov3 avatar Aug 23 '22 14:08 RustamKarimov3

@jbaccarelli-equinix Can you share some example code of how you set this up?

jpvajda avatar Aug 24 '22 18:08 jpvajda

Hey @jbaccarelli-equinix 👋

I believe what you're seeing was due to the fact that onCompleted was triggered by cache writes. We fixed this in 3.8.0 via https://github.com/apollographql/apollo-client/pull/10340. Try upgrading to 3.8.0 or greater.

As such, I'm going to go ahead and close this out. Feel free to reopen if I've made a mistake!

jerelmiller avatar Feb 15 '24 00:02 jerelmiller

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

github-actions[bot] avatar Feb 15 '24 00:02 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.

github-actions[bot] avatar Mar 16 '24 00:03 github-actions[bot]