LimeChain / matchstick

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

`@derivedFrom` fields null if `id: Bytes!` #393

Closed sebastiantf closed 11 months ago

sebastiantf commented 1 year ago

Derived fields of entities are null if the source entity has an id of type Bytes

Example:

Before:

type ERC721Campaign @entity {
  id: ID!
  //...
  claims: [ERC721Claim!]! @derivedFrom(field: "erc721Campaign")
}

type ERC721Claim @entity(immutable: true) {
  id: ID!
  //...
  erc721Campaign: ERC721Campaign!
}

After:

type ERC721Campaign @entity {
  id: Bytes!
  //...
  claims: [ERC721Claim!]! @derivedFrom(field: "erc721Campaign")
}

type ERC721Claim @entity(immutable: true) {
  id: ID!
  //...
  erc721Campaign: ERC721Campaign!
}

only changed the ERC721Campaign.id from ID to Bytes and made corresponding changes to mappings now both the below asserts that used to work are erroring with Cannot return null for a required field.

assert.assertNotNull(erc721Campaign.get("claims"))
assert.assertNotNull(erc721Campaign.claims)

logStore() doesn't contain claims List either

sebastiantf commented 1 year ago

Seemingly related issue: Following assertion works fine:

assert.assertNotNull(erc721Claim.get("erc721Campaign"))

But following fails with error:

assert.assertNotNull(erc721Claim.erc721Campaign) // intellisense says type is `Bytes`
/*
ERROR TS2322: Type '~lib/@graphprotocol/graph-ts/common/collections/ByteArray | null' is not assignable to type '~lib/@graphprotocol/graph-ts/common/collections/ByteArray'.

     assertTrue(value != null);
                         ~~~~
 in ~lib/matchstick-as/assembly/assert.ts(70,25)
*/

The stacktrace is also confusing with the above error

sebastiantf commented 1 year ago

Among other things, issue seems to be caused by this, fixing of which would require several further changes + refactoring all over: if derived_field_value.is_string()

https://github.com/LimeChain/matchstick/blob/578b9c75e2e115658a59f5dbe83d95be0f1de66d/src/context/derived_fields.rs#L10-L17

dimitrovmaksim commented 11 months ago

Derived relations handling has been changed in https://github.com/LimeChain/matchstick/releases/tag/0.6.0-rc.3