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
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { replaceValue } from "../updateObject";
import { replaceValue, updateObject } from "../updateObject";
import { UpdateTreeContext } from "../types";
import { ForestRun } from "../../ForestRun";
import { gql, createTestOperation } from "../../__tests__/helpers/descriptor";
import { generateChunk } from "../../__tests__/helpers/values";
import { resolveFieldValue } from "../../values/resolve";
import { ObjectChunk } from "../../values/types";
import * as Difference from "../../diff/difference";

describe("replaceValue invariant", () => {
it("reports the operation when a scalar is replaced with an object", () => {
Expand Down Expand Up @@ -132,3 +133,56 @@ describe("incompatible object difference invariant", () => {
);
});
});

describe("divergent composite chunks", () => {
it("keeps a null field when a composite list difference reaches it", () => {
const base = generateChunk(`
query Ring0CompositeList {
emailsInfo @mock(value: null) {
address
}
}
`).value;
const listDifference = Difference.createCompositeListDifference();
listDifference.layout = [];
const difference = Difference.createObjectDifference();
Difference.addFieldDifference(difference, "emailsInfo", listDifference);
Difference.addDirtyField(difference, "emailsInfo");

const warn = jest.fn();
const context = {
operation: base.operation,
drafts: new Map(),
missingFields: new Map(),
changes: new Map(),
findParent: () => undefined,
env: {
objectKey: () => false,
logger: {
debug: jest.fn(),
log: jest.fn(),
warn,
error: jest.fn(),
},
},
} as unknown as UpdateTreeContext;

let result: ReturnType<typeof updateObject>;
expect(() => {
result = updateObject(context, base, difference);
}).not.toThrow();

expect(result).toBeUndefined();
expect(base.data.emailsInfo).toBeNull();
expect(warn).toHaveBeenCalledWith(
'Skipping update for "query Ring0CompositeList" at path emailsInfo: ' +
"field is an explicit null (CompositeNull) in this chunk, but the incoming " +
"CompositeListDifference expects a composite list; the node has divergent " +
"chunks for this field (null in one, list in another). Leaving the null value " +
"unchanged. This usually means the same node was written with conflicting " +
"values in a single operation (e.g. aliased selections or a repeated node id) " +
"or via a partial/errored write; ensure such selections resolve this field " +
"consistently.",
);
});
});
Loading