useLazyQuery no longer preserves pollInterval across calls
See original GitHub issueIntended outcome:
- start a polling lazy query
- 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:
- Created a year ago
- Comments:5 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
It was 3.6.2. I’ll follow up once we upgrade again, in about a week or so!