-
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 mutation doesn't work #4031
Comments
I think this is the same as #3992 |
Please try updating to the latest npm install apollo-client@latest apollo-cache-inmemory@latest |
tried it and no result achieved. |
same problem with |
having the same issue |
have the same problem in optimistic ui about delete mutation. |
With the latest apollo-client packages, I still have this issue where the I'm using those packages:
I have found a workaround: I need to create a new Here is a reproduction: https://codesandbox.io/s/42lqq8m9q9 |
const data = store.readQuery({ query: WIDGETS })
data.widgets = data.widgets.filter(w => w.id !== this.widget.id)
store.writeQuery({ query: WIDGETS, data }) Edit: my bad, it doesn't work. A new |
* feat: basic fonctionality, welcome and kill port widgets * fix: contrast improvements * feat: plugin/dep/vulnerability widgets design * fix: widget add/remove animation * feat: run task widget * feat: news + wip resizing * feat: nuxt * chore: removed widget example * fix: visual polish for widget transform * feat(widget): overlap detection * fix: news default/max size * feat(dashboard): sidepane transition * chore: dev api server port * fix(widget): configure tooltip * refactor(widget): generic Movable mixin * refactor(widget): resizable mixin * feat(widget): resize transition * feat(widget): resize improvements * refactor(widget): zoom factor * refactor(widget): OnGrid mixin * refactor(widget): resize handler style moved to global * chore: remove console.log * refactor: files structure * feat: improved design and layout * fix: content background vars * fix: status bar / view nav z-indexes * fix: webpack dashboard grid gap * feat(news feed): handle errors * fix(card): dimmed box shadow * fix: view nav & status bar z-index * fix: remove (wip) * feat(widget): style tweaks * feat(widget): details pane (wip) * feat: news feed widget improvements * feat(widget): custom header button * feat(news): item details pane * feat(widget): custom title * fix(news): better cache and misc fixes * feat(widget): resize left and top handles * feat(widget): transparent widget while moving/resizing * feat(news): better "big size" style * fix(news): media sizes in rich content * feat(plugin): local plugins support * fix: scrolling issue in Fx * fix: colors * fix(nav bar): more item overflowing * feat(vuln): frontend * chore: locale update * fix: image in suggestion dropdown (dev) * fix(suggestion): missing custom image * feat(view): user default plugin logo if no provided icon * feat(view): better loading UX * feat(view): button background if view is selected * feat(view): new nav indicator * feat(widget): use plugin logo as default icon * feat(widget): better widget modal * feat(widget): longDescription * fix(widget): news validate url param * feat(widget): filter widgets in add pane * feat(widget): tease upcoming widgets * chore: fix merge dev * chore: yarn install * chore: sync versions * chore: update apollo * docs: widget * fix(progress): graphql error * fix(deps): localPath * perf(plugin): faster local plugin refresh * fix(nav): center active indicator * feat(task): improved header * feat(client addon): custom component load timeout message * feat(suggestion): ping animation to improve discoverability * chore: update vue-apollo * feat(api): requestRoute * fix(suggestion): hide more info link if no link * fix(style): ul padding * test(e2e): fix plugin path * chore: change test scripts * chore(deps): upgrade * fix: build error * fix(widget): removed moving scale transform * fix(widget): resize handles style * chore(deps): unpin apollo-utilities * chore(deps): lock fix * test(e2e): fix server * fix: issue with writeQuery See: apollographql/apollo-client#4031 (comment) * test(e2e): fix tests * test(e2e): missing widgets build * fix: missing widgets dep
It seems sometimes adding an optimistic response fixes the issue: vuejs/apollo#436 |
This commit is a more conservative version of e66027c We still need to make a deep clone of observableQuery.lastResult in order to determine if future results are different (see #3992), but we can restrict the use of that snapshot to a single method, rather than replacing observableQuery.lastResult with the snapshot. Should help with #4054 and #4031.
@benjamn, can confirm that However, I do notice that when deleting items, EDIT: I saw in another issue you mentioned that results from |
@Akryum thanks man! Yes the |
I got its function confused with |
@dsanders11 To clarify, modifying result objects returned by Modifying data and then writing it back to the store is safe, since it invalidates the previous result objects, so The problem with a deep copy is that it's expensive, both because the copy itself takes time, and because identical results are no longer For those reasons, I think freezing the result objects is the only viable option here, though that would interfere with valid read-modify-write patterns, and would definitely require changing the documentation. |
@benjamn why are result objects returned by |
Why is this issue still opened? It was resolved for me by installing the latests versions of apollo-client and apollo-cache-inmemory
|
I'm using these:
=> and updates are not fired when running writeQuery. |
I just switched back to ReduxCache, and that resolved my issue, not sure I can trust InMemoryCache right now due to this. |
…bility. Part of the plan I outlined in this comment: #4464 (comment) If we could trust application code not to modify cache results, we wouldn't have to save deep snapshots of past results in order to implement isDifferentFromLastResult correctly (see #4069). Aside: why doesn't the cache just return defensive copies of all results? #4031 (comment) While you might agree that immutability is a worthwhile aspiration, it can be hard to maintain that discipline across your entire application over time, especially in a team of multiple developers. This commit implements a new freezeResults option for the InMemoryCache constructor, which (when true) causes all cache results to be frozen in development, so you can more easily detect accidental mutations. Note: mutating frozen objects only throws in strict mode, whereas it fails silently in non-strict code. ECMAScript module code automatically runs in strict mode, and most module transforms add "use strict" at the top of the generated code, so you're probably already using strict mode everywhere, though you might want to double-check. The beauty of this implementation is that it does not need to repeatedly freeze entire results, because it can shallow-freeze the root of each subtree when that object is first created. Thanks to result caching, those frozen objects can be shared between multiple different result trees without any additional freezing, and the entire result always ends up deeply frozen. The freezing happens only in non-production environments, so there is no runtime cost to using { freezeResults: true } in production. Please keep this in mind when benchmarking cache performance!
Same issue, using |
@Akryum Thanks for your reproduction, but the codesandbox you provide does not work well now. It shows an error Error sending the query 'items' TypeError: Failed to fetch , it seems that the server has something wrong. |
Was having the same issue with the UI not reflecting the updated cache. Following the example in the docs, I could not get it working unless I created a new array for
|
i had this problem too, then i inspected the record returned by the mutation and noticed that it was missing a field that the records in the cache had. i added that field to the mutation response and it worked |
@EdmundMai I thought I have the same problem. But I double checked my fields and created new array as @JamieKudla did. Still didn't solve my issue. |
Not sure if this helps, but I found it works if my collection didn't have id's returned. When it did have id's I had to write a fresh object.
eg // works with just re-creating array when no id's
export const GET_BOOKS = gql`{
books {
title
author
}
}`
addBook({
variables: {input:{ title: title.value, author: author.value }},
update: (store, { data: { book } }) => {
const data = store.readQuery({ query: GET_BOOKS }) // read books from cache
data.books = [ ...data.books, book] // create new array with our book
store.writeQuery({ query: GET_BOOKS, data}) // write back data
},
}) // with id, new data object needed
export const GET_BOOKS = gql`{
books {
id
title
author
}
}`
addBook({
variables: {input:{ title: title.value, author: author.value }},
update: (store, { data: { book } }) => {
const data = store.readQuery({ query: GET_BOOKS }) // read books from cache
const books = [ ...data.books, book] // create new array with our book
store.writeQuery({ query: GET_BOOKS, data:{...data,books} }) // write back new object with our books
},
}) |
I have the same problem but what is the different first time I add a product it updates but second it stops working... If I So as a workaround because I have to push to production on Friday is this:
TLDR: If data is not added by write query I add it manually... |
Hi @crisward & all, like, always make new object or something? the behaviour is so unpredictable, it's a nightmare... |
FYR,
After I set a new object to data like this, it works.
|
Yup, always ensure the original cache object is immutable! |
Intended outcome:
updated list of recipes be rendered
Actual outcome:
the old list get rendered
How to reproduce the issue:
follow what comes here !!!!
Versions
hi I have the following client
and for get Recipe is:
and get recipe item is :
The text was updated successfully, but these errors were encountered: