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