Polling not working in background in React Native
See original GitHub issueIntended outcome: Execute the query every 30 seconds even if the device is locked or if the app is in the background
Actual outcome:
I want to execute a query every 30 seconds so I’m using pollInterval
. Everything works fine, except when the application goes to the background because it stops from executing the query.
This is my query:
const {
loading,
error,
refetch,
data
} = useQuery(UNDELIVERED_ORDERS, {
variables: {
courier: userId
},
pollInterval: 30000,
fetchPolicy: "network-only"
})
How to reproduce the issue: Just use poll interval in React Native and press home or block the device
Versions
System: OS: Linux 5.0 Ubuntu 18.04.3 LTS (Bionic Beaver) Binaries: Node: 12.4.0 - ~/.nvm/versions/node/v12.4.0/bin/node Yarn: 1.19.2 - /usr/bin/yarn npm: 6.11.3 - ~/.nvm/versions/node/v12.4.0/bin/npm Browsers: Chrome: 78.0.3904.108 Firefox: 70.0.1 npmPackages: @apollo/react-hooks: ^3.0.1 => 3.0.1 apollo-boost: ^0.4.4 => 0.4.4 apollo-link-context: ^1.0.18 => 1.0.18 npmGlobalPackages: apollo: 2.18.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
For me, it’s only running when I have the app opened
it’s not because of apollo-client. it’s because your app is in background and not just apollo-client but all of codes stop running. you should find a way to run background task