From 5a79750eda8f646eb7083ef294239192a5af8e6d Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Fri, 30 May 2025 23:26:45 +0200 Subject: [PATCH 1/3] failing test --- .../src/__tests__/regression.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/packages/apollo-forest-run/src/__tests__/regression.test.ts b/packages/apollo-forest-run/src/__tests__/regression.test.ts index 22451bd21..ecd1541c0 100644 --- a/packages/apollo-forest-run/src/__tests__/regression.test.ts +++ b/packages/apollo-forest-run/src/__tests__/regression.test.ts @@ -998,3 +998,48 @@ test("correctly writes fragment on abstract type", () => { ], }); }); + +test("correctly handles optimistic cache.modify", () => { + const query = gql` + { + items { + id + name + } + } + `; + const foo = { __typename: "Foo", id: "1", name: "foo" }; + const bar = { __typename: "Bar", id: "2", name: "bar" }; + const cache = new ForestRun(); + + cache.write({ + dataId: "ROOT_QUERY", + query, + result: { + items: [{ ...foo }, { ...bar }], + }, + }); + + let optimisticModify; + const before = cache.diff({ query, optimistic: true }); + cache.recordOptimisticTransaction(() => { + optimisticModify = cache.modify({ + id: cache.identify(foo), + fields: { name: () => "fooChanged" }, + }); + }, "test"); + const optimisticData = cache.diff({ query, optimistic: true }); + cache.removeOptimistic("test"); + const restoredData = cache.diff({ query, optimistic: true }); + + expect(before.result).toEqual({ + items: [foo, bar], + }); + expect(optimisticData.result).toEqual({ + items: [{ ...foo, name: "fooChanged" }, bar], + }); + expect(restoredData.result).toEqual({ + items: [foo, bar], + }); + expect(optimisticModify).toBe(true); +}); From b0e6fa95b1f501ff2340ac18196b947ac26566c4 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Fri, 30 May 2025 23:43:02 +0200 Subject: [PATCH 2/3] Change files --- ...lo-forest-run-85adcd22-ca87-4f61-901a-565fc0b2a7ea.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@graphitation-apollo-forest-run-85adcd22-ca87-4f61-901a-565fc0b2a7ea.json diff --git a/change/@graphitation-apollo-forest-run-85adcd22-ca87-4f61-901a-565fc0b2a7ea.json b/change/@graphitation-apollo-forest-run-85adcd22-ca87-4f61-901a-565fc0b2a7ea.json new file mode 100644 index 000000000..638cd84fd --- /dev/null +++ b/change/@graphitation-apollo-forest-run-85adcd22-ca87-4f61-901a-565fc0b2a7ea.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix(apollo-forest-run): cache.modify within optimistic transaction", + "packageName": "@graphitation/apollo-forest-run", + "email": "vladimir.razuvaev@gmail.com", + "dependentChangeType": "patch" +} From 26d95d18fa29c656d939e040593937bf6530e96a Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Fri, 30 May 2025 23:54:02 +0200 Subject: [PATCH 3/3] one more failing test --- packages/apollo-forest-run/src/__tests__/regression.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/apollo-forest-run/src/__tests__/regression.test.ts b/packages/apollo-forest-run/src/__tests__/regression.test.ts index ecd1541c0..e1869fcbf 100644 --- a/packages/apollo-forest-run/src/__tests__/regression.test.ts +++ b/packages/apollo-forest-run/src/__tests__/regression.test.ts @@ -1043,3 +1043,7 @@ test("correctly handles optimistic cache.modify", () => { }); expect(optimisticModify).toBe(true); }); + +test("definitely fails", () => { + expect(true).toBe(false); +});