question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useLazyQuery no longer preserves pollInterval across calls

See original GitHub issue

Intended outcome:

  1. start a polling lazy query
  2. sometime later, reuse the hook to start polling again
const [
    pollForResults,
    {
      data,
      called,
      stopPolling,
      loading:,
      error
      refetch:,
    },
  ] = pollingLazyQuery({
    pollInterval,
    fetchPolicy: "network-only",
  });

pollForResults({ variables })
// some time later
pollForResults({ variables })

Actual outcome: In the second call, no polling occurs. To get polling to happen, you have to re-pass pollInterval. If you don’t, you get a single request (no polling). Example of workaround:

pollForResults({ variables })
// some time later
pollForResults({ variables, pollInterval })

How to reproduce the issue: See the above sample code

Versions This worked in Apollo Client 2 (pollInterval “stuck” from initial configuration), but it’s broken as of v3 sometime (sorry about lack of specifics on version — have been trying to do the big 2 to 3 upgrade)

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
denlahodnyicommented, Jun 14, 2022

I have the same issue on 3.6.2 - useLazyQuery with pollInterval doesn’t re-execute a query. Upgrading to the latest version (3.6.8) doesn’t help.

1reaction
benasher44commented, Jun 4, 2022

It was 3.6.2. I’ll follow up once we upgrade again, in about a week or so!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
To run a query within a React component, call useQuery and pass it a GraphQL query ... Note that if you set pollInterval...
Read more >
@apollo/client - Awesome JS
Fix issue where loading remains true after observer.refetch is called repeatedly with different variables when the same data are returned. @alessbell in #10143....
Read more >
@apollo/client | Yarn - Package Manager
Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components...
Read more >
Is it possible to prevent `useLazyQuery` queries from being re ...
But if you want to use useLazyQuery you just have to pass variables on the onClick and not directly on the useLazyQuery call....
Read more >
You probably don't need useLazyQuery ‍♂️
But React already has a more elegant way of controlling this behavior: conditional rendering. Take this component example, using useLazyQuery ( ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found