From b57e5118cc429f02b2aac03b9a16efe4720afd85 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 8 Sep 2024 01:52:36 +0200 Subject: [PATCH] Define gql merge function for "trackRecords" field of "MangaType" When opening the reader and going back to the library, the whole category of the previous opened manga gets refetched due to the readers manga query removing the mangas tracker data from the cache which is required in the library --- src/lib/requests/client/GraphQLClient.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/requests/client/GraphQLClient.ts b/src/lib/requests/client/GraphQLClient.ts index a2532095..ba396ecb 100644 --- a/src/lib/requests/client/GraphQLClient.ts +++ b/src/lib/requests/client/GraphQLClient.ts @@ -24,6 +24,22 @@ import { StrictTypedTypePolicies } from '@/lib/graphql/generated/apollo-helpers. /* eslint-disable no-underscore-dangle */ const typePolicies: StrictTypedTypePolicies = { + MangaType: { + fields: { + trackRecords: { + merge(existing, incoming) { + const nodes = incoming.nodes ?? existing?.nodes; + + return { + ...existing, + ...incoming, + totalCount: nodes?.length ?? existing?.totalCount ?? incoming.totalCount, + nodes, + }; + }, + }, + }, + }, GlobalMetaType: { keyFields: ['key'] }, ExtensionType: { keyFields: ['pkgName'] }, AboutServerPayload: { keyFields: [] },