From e29261fe6f1599eb17bcc7cb04c9de039fb2c726 Mon Sep 17 00:00:00 2001 From: Zeck Li Date: Sun, 9 Aug 2020 15:17:33 +0800 Subject: [PATCH] fix(cache): invalidate cache after followed or unfollowed a tag --- src/mutations/user/toggleFollowTag.ts | 9 +++++++++ src/types/user.ts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mutations/user/toggleFollowTag.ts b/src/mutations/user/toggleFollowTag.ts index 94b9ef8e0..e279b3bcf 100644 --- a/src/mutations/user/toggleFollowTag.ts +++ b/src/mutations/user/toggleFollowTag.ts @@ -1,3 +1,4 @@ +import { CACHE_KEYWORD, NODE_TYPES } from 'common/enums' import { AuthenticationError, TagNotFoundError } from 'common/errors' import { fromGlobalId } from 'common/utils' import { MutationToToggleFollowTagResolver } from 'definitions' @@ -38,6 +39,14 @@ const resolver: MutationToToggleFollowTagResolver = async ( await tagService.unfollow({ targetId: tag.id, userId: viewer.id }) } + // invalidate extra nodes + tag[CACHE_KEYWORD] = [ + { + id: viewer.id, + type: NODE_TYPES.user, + }, + ] + return tag } diff --git a/src/types/user.ts b/src/types/user.ts index fbf7080c5..adace5e4e 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -42,7 +42,7 @@ export default /* GraphQL */ ` @authenticate @purgeCache(type: "${NODE_TYPES.user}") "Follow or unfollow tag." - toggleFollowTag(input: ToggleItemInput!): Tag! @authenticate + toggleFollowTag(input: ToggleItemInput!): Tag! @authenticate @purgeCache(type: "${NODE_TYPES.tag}") "Follow or Unfollow current usere." toggleFollowUser(input: ToggleItemInput!): User! @authenticate