diff --git a/src/cache/inmemory/__tests__/policies.ts b/src/cache/inmemory/__tests__/policies.ts index 85ceb0af738..11c1812e141 100644 --- a/src/cache/inmemory/__tests__/policies.ts +++ b/src/cache/inmemory/__tests__/policies.ts @@ -1873,6 +1873,32 @@ describe("type policies", function () { } `; + const deleteQuery = gql` + query { + todoList { + tasks(deleteOnMerge: true) { + taskID + text + } + } + } + `; + + const deleteData = { + todoList: { + __typename: "ToDoList", + tasks: [], + }, + }; + + // This write will cause the merge function to return undefined, but + // since the field is already undefined, the undefined return from the + // merge function should not trigger the drop function. + cache.writeQuery({ + query: deleteQuery, + data: deleteData, + }); + cache.writeQuery({ query, data: { @@ -1903,23 +1929,11 @@ describe("type policies", function () { expect(cache.extract()).toMatchSnapshot(); + // Since the ToDoList.tasks field has data now, this deletion should + // trigger the drop function, unlike the last time we used deleteQuery. cache.writeQuery({ - query: gql` - query { - todoList { - tasks(deleteOnMerge: true) { - taskID - text - } - } - } - `, - data: { - todoList: { - __typename: "ToDoList", - tasks: [], - }, - }, + query: deleteQuery, + data: deleteData, }); }); });