GraphQL Apollo remove dangling references

Viewed 378

Since Apollo client 3.0 a normalised object can be deleted from the cache using cache.evict, like so:

{
  update: (cache, { data: updateData }) => {
    if (isNil(updateData)) return

    const { id } = updateData.removeSomething
    cache.evict({ id: `Something:${id}` })
    cache.gc()
  }
}

However, deleting it in this manner still seems to leave dangling pointers to the object in lists it appeared in. Appearing like so in the cache:

[{__ref: "Something:9180d367-b018-46c1-b9cf-049258408fd8"}]

How can these references to the object be removed without knowing the parent ID?

Edit: This pull request answers it to a degree, but doesn't find anything with the child ID.

1 Answers

By default when you evict an object (such as Something:${id}), references to it in the cache are not removed. The references become dangling references, means they point to a nonexistent object. These references remain in case the object is subsequently restored.

Summary, even though the cached list's contents include the dangling reference, query results for that list shouldn't

Related