Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement loadRelated #401

Closed
dimitrovmaksim opened this issue Sep 4, 2023 · 0 comments · Fixed by #399
Closed

Implement loadRelated #401

dimitrovmaksim opened this issue Sep 4, 2023 · 0 comments · Fixed by #399
Assignees
Labels
critical enhancement New feature or request

Comments

@dimitrovmaksim
Copy link
Member

dimitrovmaksim commented Sep 4, 2023

loadRelated

Description:

loadRelated is a function that allows users to load derived entities into their handlers. This was previously not possible in the graph-node, but was possible with Matchstick due a bug in the graph-cli that generated getter (and setter) functions for those fields and the way the Matchstick's own entity store works. Derived fields are virtual fields and do not actually exists in the graph-node database. Instead they are created during query time and are only accessible when querying the subgraph. More info on derived fields https://thegraph.com/docs/en/developing/creating-a-subgraph/#reverse-lookups

Matchstick's own store

Matchstick does not work with a database, but implements its own key/value entity store. In the Matchstick store the derive fields actually exists and they keep the IDs of the child entities, hence why the getter/setter functions worked in Matchstick. While this was helpful for users to test their relations, it caused a lot of issues (especially with handling both String and Byte IDs) and made the code complex.
It will probably be wise to refactor the store and make it function similarly to the graph-node, i.e dynamically construct the derived fields when requested. We already keep the derived relations in a separate derived key/value store, but it may not be needed anymore, because the child entity's name, the parent id and the derivedFrom field should come from the loadRelated function itself, which should make it easier to find it in our entity store.

Matchstick implementation:

Graph Node dependency:

We will need to update the graph-node dependencies in order to be able to implement loadRelated

Entity Store:

Looking into the function loadRelated(entity: string, id: string, field: string): Array<Entity>; function we may be able to:

  1. Simplify the matchstick store. - Currently we keep all relations into a separate derived mapping. But the function itself should provide us with the relation info we need in order to fetch the child entities from the entities store, so this mapping becomes obsolete as well as this whole module.
  2. We will no longer need to track the relations into the store directly - the derived_fields module will probably become obsolete
@dimitrovmaksim dimitrovmaksim added enhancement New feature or request critical labels Sep 4, 2023
@dimitrovmaksim dimitrovmaksim changed the title implement loadRelated Implement loadRelated Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
critical enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants