ecerroni / apollo-cache-updater

Helper for updating the apollo cache after a mutation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cache update does not rerender

john-dominguez opened this issue · comments

Issue:

When adding a new Employee, ApolloCacheUpdater successfully updates the cache but does not trigger a re-render ( shown once the page is refreshed).

Info:

REMOVE is working as intended and triggers a re-render upon completion.

Client Options:

fetchPolicy: 'cache-and-network',
errorPolicy: 'all',
notifyOnNetworkStatusChange: true,
returnPartialData: true

Image

The following image shows:

  1. Console log: Created Employee & ApolloCacheUpdater ran successfully
  2. Apollo Extension: Shows the Employee in cache
  3. Table: Empty table
  4. employees object: data object from const { loading, data, refetch } = useQuery(GET_EMPLOYEES)

Image

Solved:
Setting the fetchPolicy to 'cache-first' fixed the issue.

There's an edge case of when the table is empty and you create a new item it does not force a UI Update.

commented

@john-dominguez if you create a small repo reproducing the issue I'll be happy to have a look 👍

@john-dominguez if you create a small repo reproducing the issue I'll be happy to have a look 👍

Apologies, i couldn't figure out why it wasn't initially working. It is fixed now that i changed my rendering.