Any reason that galaxy and apollo wouldn't work? Getting extremely weird apollo-client cache behavior

Is there any reason that galaxy would cause odd caching behavior with apollo-client? It works no problem on localhost, but on galaxy I’m having some queries update other queries with data that doesn’t even exist in the DB anymore.

Example

Call a query for currentUser, get the current user as expected

Then call query to get the currentUsers “posts” (think instagram), when that query runs, it’s updating the currentUser in the cache (from previous currentUser query) with old data from an old version of the profile… even though the Post query is using a resolver to grab the latest user record from the DB…

Even weirder is this only happens in production on galaxy but not localhost.

Also, I can confirm that currentUser is returning the correct data from the back-end, but somewhere between the back-end and rendering the content (i.e. somewhere in apollo-client) I’m getting old profile names, profile pictures, etc exchanged for whatever the back-end is sending.

Again, this seems to only be with the production URL I have. And I’m getting correct data, then the other query runs, and the data gets messed up. Totally beyond me. Both are hitting same remote DB, both signed in as same user, both using same exact code, just changing the uri in HTTP link… two different outcomes.

I think maybe adding fetchPolicy: ‘network-only’ “fixed” it, but still not sure why it works no problem until production… kind of disheartening.

EDIT: fetchPolicy: ‘network-only’ didn’t fix it… still no idea what’s going on.

EDIT: I think it is possibly from not clearing dataloader, so dataloader returned an old user object that apollo matched against the current user object and thought the latest request had the latest version of the user, and thus overwrote the current user in the store…

Potentially the fix is:

export const default_Owner_Resolver = ( { ownerId }, args, { loaders, user }) => {
  let owner = loaders.userLoader.load(ownerId);
  if (!owner) { return null; }
  return owner;
};

to

export const default_Owner_Resolver = ( { ownerId }, args, { loaders, user }) => {
  let owner = loaders.userLoader.load(ownerId);
  if (!owner) { return null; }
  loaders.userLoader.clear(ownerId); // hello important line of code
  return owner;
};

1 Like