From 7ca3efe8b82803d9c3059c7fcf726792c7c91bdf Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Fri, 25 Oct 2024 10:46:58 -0400 Subject: [PATCH] doc(web): possibly ambiguous css & confusing cache policies/types --- web/components/Notifications/List.vue | 23 +++++----- web/components/Notifications/Sidebar.vue | 9 +++- web/helpers/apollo-cache.ts | 53 +++++++++++++++++++++++- 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/web/components/Notifications/List.vue b/web/components/Notifications/List.vue index 3ed46622d..decde3dcc 100644 --- a/web/components/Notifications/List.vue +++ b/web/components/Notifications/List.vue @@ -59,15 +59,16 @@ async function onLoadMore() { diff --git a/web/components/Notifications/Sidebar.vue b/web/components/Notifications/Sidebar.vue index b6536a6dd..0132078b1 100644 --- a/web/components/Notifications/Sidebar.vue +++ b/web/components/Notifications/Sidebar.vue @@ -25,12 +25,19 @@ const { teleportTarget, determineTeleportTarget } = useTeleport(); - + +
Notifications + + +
Notifications -> list + * + * The policy to modify `list`'s behavior will live in the policy for + * `Notifications`. + *------------------------------------------------------------------------**/ + const defaultCacheConfig: InMemoryCacheConfig = { typePolicies: { Notifications: { fields: { list: { + /**---------------------------------------------- + * ? Key Args Syntax + * + * the sub-list in this context means "fields from the preceding key" + * + * i.e. this means [filter.type, filter.importance], + * not [filter, type, importance] + *---------------------------------------------**/ keyArgs: ["filter", ["type", "importance"]], + + /** + * Merges incoming data into the correct offset position. copied from + * [Apollo Docs](https://www.apollographql.com/docs/react/pagination/core-api#improving-the-merge-function). + * + * This lets paginated results live as a single list in the cache, + * which simplifies our client code. + * + * @param existing + * @param incoming + * @param context + * @returns the value to be cached + */ merge(existing = [], incoming, { args }) { - // copied from https://www.apollographql.com/docs/react/pagination/core-api#improving-the-merge-function const offset = args?.filter?.offset ?? 0; const merged = existing.slice(0); @@ -22,6 +63,16 @@ const defaultCacheConfig: InMemoryCacheConfig = { Mutation: { fields: { archiveAll: { + /** + * This clears the notifications cache when `archiveAll` is called to + * ensure that notification queries are invalidated, refetched, + * and in the correct state & sorting order after this operation. + * + * @param _ existing value in cache (irrelevant to this operation) + * @param incoming result from the server + * @param apolloContext contains the cache object + * @returns the value to cache for this operation + */ merge(_, incoming, { cache }) { cache.evict({ fieldName: "notifications" }); // Run garbage collection to clean up evicted references