-
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
Changing variables in watchQuery after polling started #272
Comments
Hi Tim. If you check out the relevant portion in public watchQuery(options: WatchQueryOptions): ObservableQuery {
// Call just to get errors synchronously
getQueryDefinition(options.query);
return new ObservableQuery((observer) => {
const queryId = this.startQuery(options, (queryStoreValue: QueryStoreValue) => {
if (!queryStoreValue.loading || queryStoreValue.returnPartialData) { Since Whether or not it works, it would be great if you could distill it into a unit test that we can use to guide this issue. Check out |
@Poincare I think mutating the variables is not the right approach long term, even though it might work now. I think we should encourage people to make those immutable, and perhaps provide a method to update the query options. |
Makes sense. I guess I will leave this issue open and we'll fix it soon. |
Hey guys, thanks for the fast answers. |
You can help us design the API! What should it look like? |
Ha I'm pleasured to tell you my opinion for the API. Ok, this is my use case: (Btw I'm aware of So the first naive Idea I had, was to pass the apollo client a callback, that looks into the redux store and gets what it needs. Problem is: The url params of Something like |
Just trying to understand better - why not stop the previous observable and start a new one with new variables? |
Isn't this less efficient in terms of performance/memory? |
Not really - the overhead of creating an observable object is basically 0, everything else is handled by the cache almost exactly the same way. |
Or yeah, I guess there are also some extra things stored in Redux when you start/stop a query. So it could be less efficient, but we haven't run into that as a source of problems in our production apps. It's mostly React renders that are very costly. |
Done! #635 |
Hi,
so I'm creating an observable with the
client.watchQuery
method and watch on it.It works fine.
But let's say variables in my query changed.
How to properly handle that?
Do I really have to kill the old observable and create a new one which includes the new query?
In other words: How to change variables of a polling
ObservableQuery
in runtime?Idea: Pass in an optional callback that returns the current variables.
I ask, because doing that kill/respawn approach would require a lot of refactoring in my code.
Thanks!
The text was updated successfully, but these errors were encountered: