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.

Using useQuery with pollInterval triggers onCompleted only once

See original GitHub issue

Intended outcome:

I would expect the onCompleted callback to be fired after every poll.

Actual outcome:

onCompleted is being fired only once. First time the query is made.

How to reproduce the issue:

const { data, stopPolling } = useQuery(QUERY, {
  variables: {...},
  fetchPolicy: 'network-only',
  pollInterval: 1000,
  onCompleted: () => console.log('called')
})

Versions

npmPackages: @apollo/react-common: ^3.0.1 => 3.0.1 @apollo/react-hooks: ^3.0.1 => 3.0.1 apollo-cache-inmemory: ^1.3.5 => 1.3.11 apollo-client: ^2.6.4 => 2.6.4 apollo-link: ^1.2.3 => 1.2.4 apollo-link-context: ^1.0.10 => 1.0.10 apollo-link-error: ^1.1.1 => 1.1.2 apollo-link-http: ^1.5.5 => 1.5.7 apollo-link-logger: ^1.2.3 => 1.2.3 apollo-server-koa: ^2.1.0 => 2.2.4 apollo-utilities: ^1.3.2 => 1.3.2 react-apollo: ^2.2.4 => 2.3.2

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:41
  • Comments:39 (6 by maintainers)

github_iconTop GitHub Comments

55reactions
mamousavicommented, Dec 22, 2019

Setting notifyOnNetworkStatusChange to true solved the issue in my case.

11reactions
andreasonny83commented, Apr 29, 2020

Also, @dominik-myszkowski , setting fetchPolicy: 'network-only' only triggers the onCompleted once. I can only get it working by setting notifyOnNetworkStatusChange: true

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
When your component renders, useQuery returns an object from Apollo Client that contains loading , error , and data properties you can use...
Read more >
Poll interval option on Apollo client useQuery hook not working
I have a simple forum-like app using apollo server and client(react) and I am trying to periodically update the posts on the main...
Read more >
Components - Client (React) - Apollo GraphQL Docs
Optional for the useQuery Hook since the query can be passed in as the first ... onCompleted, (data: TData | {}) => void,...
Read more >
urql Documentation - React API
useQuery ; query, string | DocumentNode, The query to be executed. Accepts as a plain string query or GraphQL DocumentNode. ; variables ?object,...
Read more >
How to use the react-apollo.useLazyQuery function in ... - Snyk
useLazyQuery examples, based on popular ways it is used in public projects. ... to run this effect only once, otherwise we might end...
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