diff --git a/src/cache/inmemory/__tests__/policies.ts b/src/cache/inmemory/__tests__/policies.ts index e65723a56df..d520ebf5711 100644 --- a/src/cache/inmemory/__tests__/policies.ts +++ b/src/cache/inmemory/__tests__/policies.ts @@ -397,7 +397,7 @@ describe("type policies", function () { expect(result).toEqual(data); }); - it("assumes keyArgs:false when read or merge function present", function () { + it("assumes keyArgs:false when read and merge function present", function () { const cache = new InMemoryCache({ typePolicies: { TypeA: { @@ -525,7 +525,7 @@ describe("type policies", function () { expect(cache.extract()).toEqual({ ROOT_QUERY: { __typename: "Query", - types: [ + 'types({"from":"A","to":"F"})': [ { __typename: "TypeA", }, diff --git a/src/cache/inmemory/policies.ts b/src/cache/inmemory/policies.ts index 3d93bd7e780..22333fc0e37 100644 --- a/src/cache/inmemory/policies.ts +++ b/src/cache/inmemory/policies.ts @@ -324,9 +324,12 @@ export class Policies { if (typeof merge === "function") existing.merge = merge; } - if (existing.read || existing.merge) { - // If we have a read or merge function, assume keyArgs:false - // unless existing.keyFn has already been explicitly set. + if (existing.read && existing.merge) { + // If we have both a read and a merge function, assume + // keyArgs:false, because read and merge together can take + // responsibility for interpreting arguments in and out. This + // default assumption can always be overridden by specifying + // keyArgs explicitly in the FieldPolicy. existing.keyFn = existing.keyFn || simpleKeyArgsFn; } });