Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonmorixe committed Mar 8, 2022
1 parent 1bd8f0a commit 6644576
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
46 changes: 23 additions & 23 deletions src/cache/inmemory/__tests__/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -2986,7 +2986,7 @@ describe('writing to the store', () => {
}
`

expect(times).toEqual(0)
expect(times).toEqual(0);

cache.writeQuery({
query,
Expand All @@ -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: {
Expand All @@ -3020,7 +3020,7 @@ describe('writing to the store', () => {
status: "ACTIVE",
updatedAt: 100000,
},
})
});

cache.writeQuery({
query,
Expand All @@ -3033,9 +3033,9 @@ describe('writing to the store', () => {
},
},
variables: {},
})
});

expect(times).toEqual(3)
expect(times).toEqual(3);

expect(cache.extract()).toEqual({
ROOT_QUERY: {
Expand All @@ -3052,7 +3052,7 @@ describe('writing to the store', () => {
status: "ACTIVE",
updatedAt: 100000,
},
})
});

cache.writeQuery({
query,
Expand All @@ -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: {
Expand All @@ -3085,8 +3085,8 @@ describe('writing to the store', () => {
status: "PENDING",
updatedAt: 100001,
},
})
})
});
});

describe("StoreWriter", () => {
const writer = new StoreWriter(new InMemoryCache());
Expand Down
9 changes: 3 additions & 6 deletions src/cache/inmemory/writeToStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6644576

Please sign in to comment.