Skip to content

Apollo Client v4 loses all initial query data when processing @defer - only deferred fields remain in useQuery result #12976

@ItaiYosephi

Description

@ItaiYosephi

Bug Report

Critical data loss regression after upgrading from Apollo Client 3.14.0 to 4.0.7. Apollo Client v4 changed how deferred responses are processed, breaking the merge behavior.

Versions

  • Working: @apollo/client: ^3.14.0
  • Broken: @apollo/client: 4.0.7

Response Flow Comparison

I created a custom link that prints the result object in both versions

First Response: (version 3 and 4)

{
    "data": {
        "items": {
            "nodes": [
                {
                    "id": "fc5028dd-c7a1-53ca-98ed-df72e419bcf6",
                    "__typename": "Item"
                },
                {
                    "id": "f8be4846-0c59-57e3-8a13-c8eff54553d9",
                    "__typename": "Item"
                }
            ],
            "pageInfo": {
                "endCursor": "1",
                "hasNextPage": true,
                "__typename": "PageInfo"
            },
            "totalCount": 3651,
            "__typename": "ItemConnection"
        }
    },
    "hasNext": true
}

Second Response v3

{
    // ✅ COMPLETE merged data with both initial AND deferred fields
    "data": {
        "items": {
            "__typename": "ItemConnection",
            "nodes": [
                {
                    "__typename": "Item",
                    "id": "fc5028dd-c7a1-53ca-98ed-df72e419bcf6",
                    "name": "Item 1"
                },
                {
                    "__typename": "Item",
                    "id": "f8be4846-0c59-57e3-8a13-c8eff54553d9",
                    "name": "Item 2"
                }
            ],
            "pageInfo": {
                "__typename": "Item",
                "endCursor": "1",
                "hasNextPage": true
            },
            "totalCount": 3651
        }
    },
    "hasNext": false,
    "incremental": [
        {
            "data": {
                "name": "Item 1",
                "__typename": "Item"
            },
            "path": [
                "items",
                "nodes",
                0
            ]
        },
        {
            "data": {
                "name": "Item 2",
                "__typename": "Item"
            },
            "path": [
                "items",
                "nodes",
                1
            ]
        }
    ]
}

Second Response v4

{
    "data": // ❌ No complete merged data provided
    "hasNext": false,
    "incremental": [
        {
            "data": {
                "name": "Item 1",
                "__typename": "Item"
            },
            "path": [
                "items",
                "nodes",
                0
            ]
        },
        {
            "data": {
                "name": "Item 2",
                "__typename": "Item"
            },
            "path": [
                "items",
                "nodes",
                1
            ]
        }
    ]
}

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