I have a nested document that I want to store as Entries based on all contained objects. Important is that the objects are hashed based on the content of their nested objects.
I got the impression that Links are used for mutable or ad-hoc associations between Entries. So naively I wrote nested structs with address references:
Now I want to get the Beat Entry and return it as a JSON tree, including the Note. The client should not have to do the querying for the rest of the substructure. I started out retrieving the Entry:
#[zome_fn("hc_public")]
fn get_beat(address: Address) -> ZomeApiResult<Option<Entry>> {
let beat = hdk::get_entry(&address);
// the beat does not contain the nested Note, only its Vec<Address>
// use get_links_and_load? does that work for address references?
...
}
But now I’m in a predicament. I could recursively go over the addresses in the resulting struct and retrieve the sub-entries, but then there is no structure available to build up to render the actual JSON tree unless I duplicate the Beat and Note structs to support struct nesting:
I could use links and leave out the Vec<Address>, but do link contents get hashed along with the Entry? Or do hdk functions exist to retrieve nested Entry structures?
This section looks like it refers to a graphql style concept of data fetching, I haven’t learned the inner workings of it yet, but I think the hc-happ-create code generator sets you up for doing graphql style stuff. I am not sure if it would accommodate this kind of functionality you’re looking for.
Thanks! They actually do it in the frontend here using multiple calls, but I would to minimize that to a single call and do the structure merging on the backend (in the zome).
I wrote a proc macro that successfully creates tree-versions of user Entry structures, so it can stitch the Entries back together and return them as nested results from Zome HTTP API calls.