Skip to content

Commit

Permalink
Strengthen test of merge/drop function interaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Apr 29, 2021
1 parent 8948dae commit de99635
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
});
});
});
Expand Down

0 comments on commit de99635

Please sign in to comment.