3 ms·
Thats indeed something that doesn't seem to be discussed much, even if you look at graphql's presentation - https://www.youtube.com/watch?v=WQLzZf34FJ8 https://
by spion 11y ago
Thats indeed something that doesn't seem to be discussed much, even if you look at graphql's presentation - https://www.youtube.com/watch?v=WQLzZf34FJ8 https://www.youtube.com/watch?v=WQLzZf34FJ8 there seems to be a lot of redundancy when "my friends including their events" is fetched.
I imagine that a scheme based on an UUID and deduplication would work - when constructing the response an object repository is kept and if an object with the same uuid appears twice its replaced with a reference to them.
Going against the "don't extend JSON" best practice, that would be:
{
"friends": [{
"name": "Name",
"events": [#uuid1, #uuid2]
}, {
"name": "Another name",
"events": [#uuid1, #uuid2]
}],
}
#{
"uuid1": {"name": "MyEvent", "description": "..."},
"uuid2": {"name": "OtherEvent", "description": "..."},
}
And it can support cyclic references too, as a bonus. Ignoring best practices is so... liberating.
Ultimately this is just compression though. Its possible that gzip will be quite sufficient for most cases.
- emidln 11y agoTransit [1] can do this for you. [1] https://github.com/cognitect/transit-format https://github.com/cognitect/transit-format