Comments (4)
3.4 and 3.5 dealt with misbehavior in the polling function. It seems like you’re asking about a query that polls for the duration of polling sequence, and knowing that this polling sequence is havppening. If that‘s what you want, then you can use the
startPolling()
andstopPolling()
functions, along with another piece of state which indicates that you’re polling. Something like:const [polling, setPolling] = useState(true); const {data, loading, startPolling, stopPolling} = useQuery(MY_QUERY); useEffect(() => { if (polling) { startPolling(3000); } else { stopPolling(); } }, [polling]); // The polling variable can be unset in a long timeout, to achieve the use-case you want, and can be read to determine that we’re in a long poll.
Yes, using a local React state is exactly what we've done to accomplish this. However, this seems like something that ApolloClient should handle.
I’m not really sure that
notifyOnNetworkStatusChange
will do what you want here.
No, it won't, because as I said that deals only with network-level state.
ApolloClient could easily incorporate this exact type of state-tracking, and from looking at the source code it nearly does already. There are internal functions/handlers that respond to the calls startPolling()
/stopPolling()
, and between each start and stop, there is a state that we're interested in knowing about - the fact that polling is in progress. This seems like a core state of the Client that should be exposed in its API.
from apollo-feature-requests.
@brainkim
Can you please provide some information about what may have changed in that overhaul?
Is there anything specifically related to what I mentioned about the difference between network-level polling and logical polling state?
from apollo-feature-requests.
3.4 and 3.5 dealt with misbehavior in the polling function. It seems like you’re asking about a query that polls for the duration of polling sequence, and knowing that this polling sequence is havppening. If that‘s what you want, then you can use the startPolling()
and stopPolling()
functions, along with another piece of state which indicates that you’re polling. Something like:
const [polling, setPolling] = useState(true);
const {data, loading, startPolling, stopPolling} = useQuery(MY_QUERY);
useEffect(() => {
if (polling) {
startPolling(3000);
} else {
stopPolling();
}
}, [polling]);
// The polling variable can be unset in a long timeout, to achieve the use-case you want, and can be read to determine that we’re in a long poll.
I’m not really sure that notifyOnNetworkStatusChange
will do what you want here.
from apollo-feature-requests.
Sorry to hear you’re having trouble. Can you try 3.4/3.5? I did an overhaul of polling around summer-time so these sorts of issues probably should be fixed in 3.4/3.5 🤞
from apollo-feature-requests.
Related Issues (20)
- Local Resolvers: Support returning errors and data together for partial results
- Dependency Dashboard
- Revisit `refetchQueries` API
- Add an option to MockProvider to throw when a request fails to match a mock
- Please add polyfill for `globalThis` as it breaks compatibility for Chrome < v71 HOT 2
- Refetch on window focus HOT 2
- Drop `ApolloClient.query()` in next major HOT 1
- Keyword search in Job postings filter HOT 1
- warnAboutDataLoss fails with stringifying error and breaks application
- Query consolidation HOT 1
- Compare variables based on their serialized value HOT 1
- Change useSubscription to be Suspense compatible HOT 1
- Implement timeout for Apollo Client HOT 3
- Warn/error when fragments that depend on operation variables are used without them HOT 1
- Could you make error messages more informative? HOT 1
- Add @client support on argument level
- Documentation and warning about cache and merging of array types is misleading
- Reset lazy query HOT 1
- Allow unmounted queries to continue to resolve HOT 1
- Apollo Link onError should provide access to stack trace HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-feature-requests.