apollographql / apollo-client-nextjs

Apollo Client support for the Next.js App Router
https://www.npmjs.com/package/@apollo/experimental-nextjs-app-support
MIT License
358 stars 25 forks source link

Transport minified version of query. #277

Closed phryneas closed 4 weeks ago

phryneas commented 1 month ago

Right now, we transport the AST of a query over the network.

That's not optimal:

Normal Query:

  query dynamicProducts {
    products {
      id
      title
      foo {
        bar {
          baz {
            yoink
          }
        }
      }
    }
  }

is instead transported as

{
  "kind": "Document",
  "definitions": [
    {
      "kind": "OperationDefinition",
      "operation": "query",
      "name": {
        "kind": "Name",
        "value": "dynamicProducts"
      },
      "variableDefinitions": [],
      "directives": [],
      "selectionSet": {
        "kind": "SelectionSet",
        "selections": [
          {
            "kind": "Field",
            "name": {
              "kind": "Name",
              "value": "products"
            },
            "arguments": [],
            "directives": [],
            "selectionSet": {
              "kind": "SelectionSet",
              "selections": [
                {
                  "kind": "Field",
                  "name": {
                    "kind": "Name",
                    "value": "id"
                  },
                  "arguments": [],
                  "directives": []
                },
                {
                  "kind": "Field",
                  "name": {
                    "kind": "Name",
                    "value": "title"
                  },
                  "arguments": [],
                  "directives": []
                },
                {
                  "kind": "Field",
                  "name": {
                    "kind": "Name",
                    "value": "foo"
                  },
                  "arguments": [],
                  "directives": [],
                  "selectionSet": {
                    "kind": "SelectionSet",
                    "selections": [
                      {
                        "kind": "Field",
                        "name": {
                          "kind": "Name",
                          "value": "bar"
                        },
                        "arguments": [],
                        "directives": [],
                        "selectionSet": {
                          "kind": "SelectionSet",
                          "selections": [
                            {
                              "kind": "Field",
                              "name": {
                                "kind": "Name",
                                "value": "baz"
                              },
                              "arguments": [],
                              "directives": [],
                              "selectionSet": {
                                "kind": "SelectionSet",
                                "selections": [
                                  {
                                    "kind": "Field",
                                    "name": {
                                      "kind": "Name",
                                      "value": "yoink"
                                    },
                                    "arguments": [],
                                    "directives": []
                                  }
                                ]
                              }
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ],
  "loc": {
    "start": 0,
    "end": 163
  }
}

and instead we could go smaller and transport

query dynamicProducts{products{id title foo{bar{baz{yoink}}}}}
relativeci[bot] commented 1 month ago

Job #133: Bundle Size — 1.01MiB (~+0.01%).

e38de2b(current) vs 1f8cda5 main#115(baseline)

[!WARNING] Bundle contains 1 duplicate package – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
Job #133
     Baseline
Job #115
Regression  Initial JS 890.63KiB(~+0.01%) 890.58KiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 1.5% 0%
No change  Chunks 24 24
No change  Assets 45 45
No change  Modules 512 512
No change  Duplicate Modules 30 30
No change  Duplicate Code 1.29% 1.29%
No change  Packages 29 29
No change  Duplicate Packages 1 1

Bundle size by type  Change 1 change Regression 1 regression
|            |       Current
[Job #133](https://app.relative-ci.com/projects/fukE5WxC5RnzLcZncFJw/jobs/133-ZCsRYJqGokQEppPZOw52?utm_source=github&utm_medium=pr-report "View job report") |      Baseline
[Job #115](https://app.relative-ci.com/projects/fukE5WxC5RnzLcZncFJw/jobs/115-9xgEFBbUDuVGFYBVjWlB?utm_source=github&utm_medium=pr-report "View baseline job report") | |:--|--:|--:| | Regression  [JS](https://app.relative-ci.com/projects/fukE5WxC5RnzLcZncFJw/jobs/133-ZCsRYJqGokQEppPZOw52/assets?ba=%7B%22filters%22%3A%22ft.CSS-0_ft.JS-1_ft.IMG-0_ft.MEDIA-0_ft.FONT-0_ft.HTML-0_ft.OTHER-0%22%7D "View JS assets") | `1023.89KiB` (`~+0.01%`) | `1023.84KiB` | | Not changed  [Other](https://app.relative-ci.com/projects/fukE5WxC5RnzLcZncFJw/jobs/133-ZCsRYJqGokQEppPZOw52/assets?ba=%7B%22filters%22%3A%22ft.CSS-0_ft.JS-0_ft.IMG-0_ft.MEDIA-0_ft.FONT-0_ft.HTML-0_ft.OTHER-1%22%7D "View Other assets") | `5.99KiB` | `5.99KiB` |

View job #133 reportView pr/transport-minified-queries branch activityView project dashboard

vercel[bot] commented 4 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
apollo-client-nextjs-experimental-nextjs-app-support ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2024 10:51am