-
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
Fix refetchQueries context #3580
Conversation
Let me know if there is something more I need to fix :-). |
Btw, this is currently a blocking issue for me so would be nice to have it released in a patch version. |
I kind of feel better solution would be:
where we explicitly state which context to use. |
Yes, perhaps it should be possible to use separate context for the mutation and the refetchQueries. However I think the expected default behavior would be that the context specified in the component is used for all requests that that component makes. At the very least, using the same context is better than using no context at all for refetchQueries and it is an easy fix. Then a way to override the default behavior and use separate contexts could be added in another PR, because I think that would require more discussion. |
Then |
One more thing that I noticed was that previous version of the package reused same context as cached query when using string value for refetchQueries. Now that is gone. But this could also be somehow connected to react-apollo changes. Didn't find which change affected this feature yet. |
I agree on that, but I don't think The fix is in this PR is very simple, it requires a change to a single line of code, and I think it could just be a patch version bump. It was implemented as suggested by @hwillson in #3576 comment. Adding a new feature to handle contexts separately for each refetchquery probably requires a minor version bump, and I think that will be eventually covered by #2009. |
Hi all - I've been digging through this further, and think we might need to change direction here.
Another option is to consider only overriding the Adding a bit more insult to injury - updating the For now, I think the best way forward here might be to handle this through documentation. We could update the
@jonaskello @horva Any objections to this approach? Additionally I'll flag this for reconsideration as part of the Apollo Client 3.x release. Thanks! |
@hwillson In the end I went a different route without apollo since I needed to solve this. However I have some comments:
|
Thanks for the feedback @jonaskello. Regarding 1 - they should use their original context. I'll be adding a test to this PR that demonstrates this. Regarding 2 - right now the context is stored as part of the Okay - I'm going to update this PR to cover the changes I discussed earlier, and get it merged (that way you'll still get the contribution credit 👍). Thanks for your contribution and time! |
Mention that `context` changes are applied to the mutation only, not `refetchQueries`.
These changes adjust `mutate`'s `refetchQueries` option to allow queries to include a custom `context` option. This `context` will then be used when refetching the query, overridding any `context` that was previsouly set with the query, when it first ran. These changes are a continuation of #3580. They do not include automatically setting the `context` of refetched queries to say the `context` used for the parent mutation. A `context` has to be specified with each refetched query, if needed. This was done to maintain backwards compatibilty (e.g. preventing issues that might arise by all of a sudden running refetched queries with a mutation `context`, that wasn't explicitly requested).
* Allow `context` option in `refetchQueries` These changes adjust `mutate`'s `refetchQueries` option to allow queries to include a custom `context` option. This `context` will then be used when refetching the query, overridding any `context` that was previsouly set with the query, when it first ran. These changes are a continuation of #3580. They do not include automatically setting the `context` of refetched queries to say the `context` used for the parent mutation. A `context` has to be specified with each refetched query, if needed. This was done to maintain backwards compatibilty (e.g. preventing issues that might arise by all of a sudden running refetched queries with a mutation `context`, that wasn't explicitly requested). * PR link update
Fixes #3576