Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polling #153

Merged
merged 9 commits into from
May 2, 2016
Merged

Polling #153

merged 9 commits into from
May 2, 2016

Conversation

jbaxleyiii
Copy link
Contributor

@jbaxleyiii jbaxleyiii commented Apr 26, 2016

Added ability to poll endpoint on a per query basis

Per #145

Docs:

One way to create a reactive-esque query is to use polling. Apollo accepts a pollInterval on the WatchQueryOptions which is the interval that a forced refetch will be called.

const handle = client.watchQuery({
  query: `
    query getCategory($categoryId: Int!) {
      category(id: $categoryId) {
        name
        color
      }
    }
  `,
  variables: {
    categoryId: 5,
  },
  forceFetch: false,
  returnPartialData: true,
  pollInterval: 1000, // ms to poll
});

Some cases may call for the ability to dynamically stop or start a polling interval on an existing query. The subscription handle returned by handle.subscribe() includes stopPolling and startPolling methods. These can be used like so:

const handle = client.watchQuery({
  query: `
    query getCategory($categoryId: Int!) {
      category(id: $categoryId) {
        name
        color
      }
    }
  `,
  variables: {
    categoryId: 5,
  },
  forceFetch: false,
  returnPartialData: true,
});

const subscription = handle.subscribe();

subscription.startPolling(50) // 50 ms poll starting
subscription.stopPolling() // stop polling

Docs PR: https://github.com/apollostack/docs/pull/53

@jbaxleyiii jbaxleyiii changed the title Polling [WIP] Polling Apr 26, 2016
@jbaxleyiii jbaxleyiii changed the title [WIP] Polling Polling Apr 29, 2016
@jbaxleyiii
Copy link
Contributor Author

@stubailo I think this should be good to. I'll open a PR on the docs as well

@stubailo
Copy link
Contributor

@martijnwalraven @Urigo one thing I'm not sure about - should these helper functions be on the subscription handle, or the observable itself? It's a bit odd that refetch or startPolling will actually affect all subscribers, but the function is on the handle.. although it would be inconvenient to have to pass around two objects everywhere.

@stubailo
Copy link
Contributor

stubailo commented May 2, 2016

Filed a followup issue, this looks amazing though!

@stubailo
Copy link
Contributor

stubailo commented May 2, 2016

#164

@stubailo stubailo merged commit 92c5a91 into master May 2, 2016
@jbaxleyiii jbaxleyiii deleted the polling branch May 17, 2016 02:04
jbaxleyiii pushed a commit that referenced this pull request Oct 18, 2017
Update Redux devtools setup syntax
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants