From 664457691c60e81c674f5306d61e5fb7a4aebb64 Mon Sep 17 00:00:00 2001 From: Gaston Morixe Date: Tue, 8 Mar 2022 15:31:49 -0300 Subject: [PATCH] fix formatting --- src/cache/inmemory/__tests__/writeToStore.ts | 46 ++++++++++---------- src/cache/inmemory/writeToStore.ts | 9 ++-- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/cache/inmemory/__tests__/writeToStore.ts b/src/cache/inmemory/__tests__/writeToStore.ts index b870256366f..af31097b50e 100644 --- a/src/cache/inmemory/__tests__/writeToStore.ts +++ b/src/cache/inmemory/__tests__/writeToStore.ts @@ -2938,41 +2938,41 @@ describe('writing to the store', () => { }); it("root type policy merge is called before cache deep merge", () => { - const personMergeMock = jest.fn() + const personMergeMock = jest.fn(); - let times = 0 + let times = 0; const cache = new InMemoryCache({ typePolicies: { Person: { merge(existing, incoming, tools) { - times++ + times++; personMergeMock({ times, existing, incoming, - }) + }); if (tools.isReference(existing) && !tools.isReference(incoming)) { - const cachedData = tools.cache.data.lookup(existing.__ref) - const existingUpdatedAt = cachedData?.["updatedAt"] - const incomingUpdatedAt = incoming?.["updatedAt"] + const cachedData = tools.cache.data.lookup(existing.__ref); + const existingUpdatedAt = cachedData?.["updatedAt"]; + const incomingUpdatedAt = incoming?.["updatedAt"]; if ( typeof existingUpdatedAt === "number" && typeof incomingUpdatedAt === "number" && existingUpdatedAt > incomingUpdatedAt ) { - return existing + return existing; } } - return tools.mergeObjects(existing, incoming) + return tools.mergeObjects(existing, incoming); }, }, }, - }) + }); - expect(times).toEqual(0) + expect(times).toEqual(0); const query = gql` query Person($offset: Int, $limit: Int) { @@ -2986,7 +2986,7 @@ describe('writing to the store', () => { } ` - expect(times).toEqual(0) + expect(times).toEqual(0); cache.writeQuery({ query, @@ -3001,9 +3001,9 @@ describe('writing to the store', () => { }, }, variables: {}, - }) + }); - expect(times).toEqual(2) // TODO: ideally this should only be called once here + expect(times).toEqual(2); // TODO: ideally this should only be called once expect(cache.extract()).toEqual({ ROOT_QUERY: { @@ -3020,7 +3020,7 @@ describe('writing to the store', () => { status: "ACTIVE", updatedAt: 100000, }, - }) + }); cache.writeQuery({ query, @@ -3033,9 +3033,9 @@ describe('writing to the store', () => { }, }, variables: {}, - }) + }); - expect(times).toEqual(3) + expect(times).toEqual(3); expect(cache.extract()).toEqual({ ROOT_QUERY: { @@ -3052,7 +3052,7 @@ describe('writing to the store', () => { status: "ACTIVE", updatedAt: 100000, }, - }) + }); cache.writeQuery({ query, @@ -3065,10 +3065,10 @@ describe('writing to the store', () => { }, }, variables: {}, - }) + }); - expect(personMergeMock.mock.calls).toMatchSnapshot() - expect(times).toEqual(4) + expect(personMergeMock.mock.calls).toMatchSnapshot(); + expect(times).toEqual(4); expect(cache.extract()).toEqual({ ROOT_QUERY: { @@ -3085,8 +3085,8 @@ describe('writing to the store', () => { status: "PENDING", updatedAt: 100001, }, - }) - }) + }); + }); describe("StoreWriter", () => { const writer = new StoreWriter(new InMemoryCache()); diff --git a/src/cache/inmemory/writeToStore.ts b/src/cache/inmemory/writeToStore.ts index 2c1fc9c9793..280469f2f3b 100644 --- a/src/cache/inmemory/writeToStore.ts +++ b/src/cache/inmemory/writeToStore.ts @@ -421,23 +421,20 @@ export class StoreWriter { previous.mergeTree = mergeMergeTrees(previous.mergeTree, mergeTree); fieldNodeSet.forEach(field => previous.fieldNodeSet.add(field)); } else { - + // Add the policy type's merge function for individual upcoming payloads if(typename && mergeTreeIsEmpty(mergeTree)) { const typePolicy = policies.getTypePolicy( typename, ); - - const merge = typePolicy.merge - + const merge = typePolicy.merge; if (merge) { mergeTree.info = { - field: undefined as any, // !!! + field: undefined as any, typename, merge, }; } } - context.incomingById.set(dataId, { storeObject: incoming,