How does Apollo Client + Apollo Server handle duplicate related nodes in the same query?
Say I have this query:
query {
parents {
id
name
child {
id
name
secondChild {
id
name
}
}
}
}
The response has a duplicate related node (the secondChild node with an ID of sc1). Is the data for that node sent over the network twice? Or is Apollo smart enough to just send it once?
res = [
{
id: p1
name: "Parent one"
child[
{
id: c1
name: "Child one"
secondChild: { # This is duplicated below
id: sc1
name: "Second Child one"
}
},
{
id: c2
name: "Child two"
secondChild: { # This is duplicated above
id: sc1
name: "Second Child one"
}
}
]
}]
This example is very simple but imagine the payload of sc1 was larger and it was repeated many more times.
I followed Tarun suggestion and checked the network response to my apollo-server. It's looks like no, Apollo does not optimize you network calls when fetching duplicate records.
Although it would be a nice feature to be implemented. Maybe you can create an issue in their github with this suggestion to see if they put this is their dev pipeline. Or you can try to implement yourself and create a pull request to share it with the rest of us. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With