LimeChain / matchstick

🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️
MIT License
207 stars 17 forks source link

@derivedFrom unexpected null #375

Closed jbrumwell closed 1 year ago

jbrumwell commented 1 year ago

Given the following schema

holders: [OfferHolder!]! @derivedFrom(field: "offer")

If there are no holders shouldn't it return an empty array? I have an older subgraph that works in this way and couldn't find any documentation on if this has changed?

With the above calling

offers.holders.length

results in an unexpected null error, alternatively if I make the field look this way

holders: [OfferHolder!] @derivedFrom(field: "offer")

It always returns null even if there are holders present

dimitrovmaksim commented 1 year ago

Hi, I'll need more context where and how do you set/use the derived fields, but generally you cannot set or get those fields in the mappings as stated here in the documentation https://thegraph.com/docs/en/developing/creating-a-subgraph/#reverse-lookups. Currently there's a bug in graph-cli, that incorrectly creates getter and setter methods for those fields described in this issue https://github.com/graphprotocol/graph-cli/issues/943

jbrumwell commented 1 year ago

@dimitrovmaksim thanks for the reply :) Yeah we don't set derived fields manually, but wasn't aware that we should avoid the accessors of these relationships.

I have multiple graphs that use these to update dependencies on child entities, In my case should I manage these dependencies on my own, or is there a recommended workaround?