Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/apollo-forest-run/src/__tests__/regression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,46 @@ test("bad manual writes shouldn't cause invariant violation", () => {
expect(cache.readQuery({ query })).toEqual({ foo: { bar: "baz" } });
});

test("malformed update result shouldn't corrupt a fresh query tree", () => {
const nodeByIdQuery = gql`
query ConsumerNodeByIdQuery($nodeId: ID!) {
nodeByID(nodeId: $nodeId) {
__typename
id
state
}
}
`;
const variables = { nodeId: "node-1" };
const node = {
__typename: "Node",
id: "node-1",
state: "active",
};
const cache = new ForestRun();

const previousValues = { nodeByID: node };

// A malformed update spreads an entity into the operation root. Installing
// it as a fresh tree indexes both the query root and child with the same key.
cache.writeQuery({
query: nodeByIdQuery,
variables,
data: { ...previousValues, ...node },
});

const writeNullNodeResult = () =>
cache.writeQuery({
query: nodeByIdQuery,
variables,
data: {
nodeByID: null,
},
});

expect(writeNullNodeResult).not.toThrow();
});

test("writes of non-object data should not throw", () => {
// Note: this is a no-op in Apollo today
const query = gql`
Expand Down
Loading