Link to cleanup queries and make them smaller

In my codebase I work with collocated fragments next to my components. As a result my queries end up being gigantic, because of all the fragment definitions and being used multiple times, I’m talking a few thousand lines long. The actual fields being requested are not that many. If I wrote the same query without using fragments and not repeating fields, the same query would be less than 200 lines.

Is there any apollo link or anything will do this automatically? This would not change the response from the server but it would make the requests a lot smaller.

1 Like

I’ve been investigating and probably persisted queries is the way to go here. Anyway I think it would be interesting that queries are cleaned up before sending them to the backend. By cleaning up I mean the following.

query x {
  myField {
    ...ComponentA
    ...ComponentB
    ...ComponentC
  }
}
fragment ComponentA {
  a
  b
  c
}
fragment ComponentB {
  b
  c
}
fragment ComponentC {
  c
  d
  e
}

gets turned into

query x {
  myField {
    a
    b
    c
    d
    e
  }
}