Skip to content

[3.9.5 but reproducible on latest] DeepMerger returns incorrect results when merging incremental arrays into existing data #12660

@varunbezzam

Description

@varunbezzam

Issue Description

We have code that fetches arrays of data in the incremental responses using the @defer directive. When the previous data that is already cached is a superset of the data that is returned in the incremental response, the merging in of incremental data into existing data is incorrect. We expect the incremental data to replace the existing data entirely since it is missing some of the elements in the existing data, but this is not happening currently.

Link to Reproduction

Reproducible with a unit test as shown below:

Reproduction Steps

Please add:

it("should merge arrays of objects", function () {
    const a = [{ a: 1, b: 2 }, { c: 3, d: 4 }];
    const b = [{ a: 1, b: 2 }];
    const merger = new DeepMerger();
    expect(merger.merge(a, b)).toEqual([{ a: 1, b: 2 }]);
  });

into mergeDeep.ts tests since this reproduces our use case.

@apollo/client version

3.9.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions