Giter VIP home page Giter VIP logo

Comments (4)

don-hover avatar don-hover commented on May 30, 2024 8

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.

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.

don-hover avatar don-hover commented on May 30, 2024 1

@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.

brainkim avatar brainkim commented on May 30, 2024 1

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.

brainkim avatar brainkim commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.