Skip to content

Commit

Permalink
fix(cache): invalidate cache after followed or unfollowed a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
devformatters authored and Zeck Li committed Aug 9, 2020
1 parent c50109e commit e29261f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/mutations/user/toggleFollowTag.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e29261f

Please sign in to comment.