-
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
Garbage collection not removing references edited by writeFragment #10307
Comments
Using |
The default mutation example in the client docs suggests using update(cache, { data: { addTodo } }) {
cache.modify({
fields: {
todos(existingTodos = []) {
const newTodoRef = cache.writeFragment({
data: addTodo,
fragment: gql`
fragment NewTodo on Todo {
id
type
}
`
});
return [...existingTodos, newTodoRef];
}
}
});
} This seems to mean that if we use the default recommended example for these kind of updates, those objects will be always immune to garbage collection. I found this when trying to expand on the getting started example to remove things and then found they didn't disappear when running |
I ran into this too. One workaround is to call Using @hwride's code above as an example: update(cache, { data: { addTodo } }) {
cache.modify({
fields: {
todos(existingTodos = []) {
const newTodoRef = cache.writeFragment({
data: addTodo,
fragment: gql`
fragment NewTodo on Todo {
id
type
}
`
});
if (cache instanceof InMemoryCache && newTodoRef) {
const newTodoId = cache.identify(newTodoRef);
if (newTodoId) {
apolloClient.cache.release(newTodoId);
}
}
return [...existingTodos, newTodoRef];
}
}
});
} Note that |
Intended outcome:
When references are not reachable via normal query, running
cache.gc()
will remove the objects from cache regardless of the reference being edited usingwriteFragment
Actual outcome:
References that were edited using
writeFragment
are not deleted even though they are otherwise unreachable via normal query callingcache.gc()
will not remove them.How to reproduce the issue:
Reproduced sandbox
writeQuery
writeFragment
writeFragment
has not been removed.Versions
The text was updated successfully, but these errors were encountered: