-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 endpoint #145
Comments
Idea: it could be beneficial to poll just part of a query, depending on how big your queries are. |
We could have the base polling method on the client itself, then expose the API to the react-apollo. If it gets added as an argument to watch query it would be one in the same |
Also along this, do we expose the handle as |
Definitely for this 100%!
Negative, I think we should avoid using |
const queryObservable = client.watchQuery({
query: `
query getCategory($categoryId: Int!) {
category(id: $categoryId) {
name
color
}
}
`,
variables: {
categoryId: 5,
},
forceFetch: false,
returnPartialData: true,
pollInterval: 1000, // ms to poll
});
const subscription = queryObservable.subscribe({
next: (graphQLResult, done) => {
const { errors, data } = graphQLResult;
if (data) {
console.log('got data', data);
}
if (errors) {
console.log('got some GraphQL execution errors', errors);
}
done() // stop watching the query OR just stop polling?
},
error: (error, done) => {
console.log('there was an error sending the query', error);
done() // stop watching the query OR just stop polling?
}
}); I think adding the interval to the object is the easiest entry point. The question is should the second argument of the observer functions stop the subscription (what I would expect) or just stop polling (confusing if you aren't polling). If it stops the entire query subscription, will we still need a way to stop the polling on its own? |
I think it's ok if you sometimes need to tear down the query and start it again to do certain things? In most cases we should be able to make that synchronous if the data is already in the store. |
@stubailo I did this on the flight out. I'll push it up as soon as I can (just landed). I didn't find the second argument needed BTW so the only change is adding pollInterval |
Final design for first run: 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
});
// extra methods
const subscription = handle.subscribe();
subscription.stopPolling();
subscription.startPolling(100); |
Merged, and released as |
Fix the wrong import for 'Kind' and add it to all code snippets #145
Simple implementation could just be polling interval.
Let's discuss API design!
@stubailo
The text was updated successfully, but these errors were encountered: