4
votes

does anyone knows how to perform cache invalidation in apollo?

I'm setting cache hints in resolvers:

export default (root, args, { userId }, { cacheControl }) => {
  cacheControl.setCacheHint({ maxAge: 60 });

  return userId && Meteor.users.findOne(userId);
};

But if something is changes and maxAge is big enough changes would not be reflected.

I'm now thinking about calling cacheControl.setCacheHint({ maxAge: 0 }) in mutations, are there any other ways of doing this?

1
I got the same problem, did you solve the issue? Thanks. - Ron

1 Answers

0
votes

You can check this: https://github.com/lucasconstantino/apollo-cache-invalidation#readme

You can use the Function matching

const randomKeyMatch = key => Math.random() >= 0.5

const update = invalidateFields(() => [
  [randomKeyMatch, 'happy']
])

client.mutate({ mutation, update })