-
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
update fails if a query has not yet been executed #2007
Comments
This issue has been automatically marked as stale becuase it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Apollo Client! |
The issue still exists -- see also #2024 |
I'm running into the same exact use case and having |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to Apollo Client! |
hmm, I'm not sure about this. I'd love to hear some thoughts on this and will add this to the post 2.0 milestone to at least improve the docs on this, or actually make a change |
There could still be a clear distinction between |
I agree that something needs to be done here. The example code in the docs at http://dev.apollodata.com/react/cache-updates.html is problematic because it does not catch the error in the case when the updated query has not yet been executed. We would need to add a catch clause to every such update which results in too much boilerplate for writing update code. |
Also, it feels wrong to manage control flow through try/catch in this way -- a query that hasn't been executed yet is not necessarily an exception, it may well be a valid use case. |
Yea, i would like some solution too, because try/catch its not ideal at all if you use some-kind of logs for errors (sentry etc.). |
Hello, any updates here? Are you accepting PR on that? What is the desired solution? Return null? Looks like a simple change here will fix the problem
This condition is inside read apollo-client/packages/apollo-cache-inmemory/src/inMemoryCache.ts Lines 75 to 89 in 3cc1967
cc @jbaxleyiii |
The same problem exists in The only decent workaround I found is using |
any updates on this? |
any update ? Same happening with Here is the error that I'm getting. I'm manually calling
|
To help provide a more clear separation between feature requests / discussions and bugs, and to help clean up the feature request / discussion backlog, Apollo Client feature requests / discussions are now being managed under the https://github.com/apollographql/apollo-feature-requests repository. Migrated to: apollographql/apollo-feature-requests#1 |
Not sure if this is a bug or intended behaviour, however, it doesn't work for my use case. The same thing has been reported (and fixed) for
refetchQueries
(see #690), although I do realise that this case is different.Intended outcome:
I'm executing a mutation query which afterwards requires a manual update of the store. However, I cannot guarantee that the query I want to update has been run with the exact parameters already. If the query has not yet been executed I don't care about the update, since the result must be fetched from the server anyway.
(A simple example to illustrate the issue: consider a simple to do app. The user can view pending tasks and completed tasks. Also, the user can mark a pending task as done. The main view only shows (and queries for) pending tasks, since always loading the large number of completed tasks would impact performace. If the user marks a pending task as done, the query for completed tasks should be updated, but may not have been executed before.)
Actual outcome:
I'm using
update
to manually update the store. If the query I want to update has not yet been run,proxy.readQuery()
will throw an error.For my use case it would be better to return
null
, so that I can decide myself what to do in this case (which would be to just do nothing). I realise I could achieve this with try/catch, but this feels wrong.How to reproduce the issue:
Execute a mutation query with an update method, which tries to read a query from the store that has not yet been executed (using the DataProxy's
readQuery()
method).Version
The text was updated successfully, but these errors were encountered: