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

Could not create WasmInstance from valid module with context: unknown import: index::store.loadRelated has not been defined' #1376

Open
hexzerodev opened this issue Jun 17, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@hexzerodev
Copy link

hexzerodev commented Jun 17, 2023

Which packages are impacted by your issue?

@graphprotocol/graph-cli

Describe the issue

Trying to run unit tests in my subgraph but getting an error:

Could not create WasmInstance from valid module with context: unknown import: `index::store.loadRelated` has not been defined'

Here the versions im using

"dependencies": {
    "@graphprotocol/graph-cli": "0.51.1",
    "@graphprotocol/graph-ts": "0.31.0"
  },
  "devDependencies": { "matchstick-as": "0.5.0" }

Here's a minimal reproducible example https://github.com/hexzerodev/subgraph-load-related-error

The error pops up when running graph test

Reproduction

https://github.com/hexzerodev/subgraph-load-related-error

Steps to Reproduce the Bug or Issue

1. npm install
2. graph test

Expected behavior

Test to be compiled properly

Screenshots or Videos

No response

Platform

- OS: Mac
- NodeJS: 19.8.1
- `@graphprotocol/*` version(s): v0.51.1

Subgraph Manifest

specVersion: 0.0.5
description: 'example of a subgraph'
repository: https://github.com/graphprotocol/graph-tooling.git
schema:
  file: ./schema.graphql
dataSources:
  - kind: ethereum/contract
    name: ExampleSubgraph
    network: mainnet
    source:
      address: '0x22843e74c59580b3eaf6c233fa67d8b7c561a835'
      abi: ExampleContract
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      file: ./src/mapping.ts
      entities:
        - ExampleEntity
        - OtherEntity
      abis:
        - name: ExampleContract
          file: ./abis/ExampleContract.json
      eventHandlers:
        - event: ExampleEvent(indexed string)
          handler: handleExampleEvent

Subgraph GraphQL Schema

type ExampleEntity @entity {
  id: ID!

  optionalBoolean: Boolean
  requiredBoolean: Boolean!
  optionalBooleanList: [Boolean!]
  requiredBooleanList: [Boolean!]!

  optionalString: String
  requiredString: String!
  optionalStringList: [String!]
  requiredStringList: [String!]!

  optionalBytes: Bytes
  requiredBytes: Bytes!
  optionalBytesList: [Bytes!]
  requiredBytesList: [Bytes!]!

  optionalInt: Int
  requiredInt: Int!
  optionalIntList: [Int!]
  requiredIntList: [Int!]!

  optionalBigInt: BigInt
  requiredBigInt: BigInt!
  optionalBigIntList: [BigInt!]
  requiredBigIntList: [BigInt!]!

  optionalReference: OtherEntity
  requiredReference: OtherEntity!
  optionalReferenceList: [OtherEntity!]
  requiredReferenceList: [OtherEntity!]!
}

type OtherEntity @entity {
  id: ID!
}

type User @entity {
  id: ID!
  objects: [Object!]! @derivedFrom(field: "owner")
}

type Object @entity {
  id: ID!
  owner: User
}

Additional context

No response

@hexzerodev hexzerodev added the bug Something isn't working label Jun 17, 2023
@azf20
Copy link
Contributor

azf20 commented Jun 19, 2023

@dimitrovmaksim @georg-getz do we need to update Matchstick for the new loadRelated functions?

@dimitrovmaksim
Copy link
Member

Hey @azf20, sorry for the late reply. Yeah all the new functions would need to be added/mocked in Matchstick.

@EdsonAlcala
Copy link

EdsonAlcala commented Aug 3, 2023

I'm facing the same issue, how do I fix it?

Update: I think I understand the issue, it seems it is new functionality in the subgraph that has to be implemented in matchstick-as.

@parkerburchett
Copy link

parkerburchett commented Aug 6, 2023

I'm running into the same issue.

Has anyone figured out how to write unit tests for this kind of relationship?
Where a User has an array of Objects that gets added, removed, changed in response to new events?

This is what the documentation currently says
https://thegraph.com/docs/en/developing/assemblyscript-api/#loading-entities-from-the-store

Looking up derived entities⁠#Link to this section
As of graph-node v0.31.0, @graphprotocol/graph-ts v0.31.0 and @graphprotocol/graph-cli v0.51.0 the loadRelated method is available.

This enables loading derived entity fields from within an event handler. For example, given the following schema:

type Token @entity {
  id: ID!
  holder: Holder!
  color: String
}

type Holder @entity {
  id: ID!
  tokens: [Token!]! @derivedFrom(field: "holder")
}

The following code will load the Token entity that the Holder entity was derived from:


let holder = Holder.load('test-id')
// Load the Token entity that the Holder entity was derived from
let token = holder.tokens.load()

This method fails with matchstick-as with this error


 Compile subgraphERROR TS2339: Property 'loadRelated' does not exist on type '~lib/@graphprotocol/graph-ts/index/store'.

     let value = store.loadRelated(this._entity, this._id, this._field);

@Preston-Harrison
Copy link

Also running into this problem. Is anyone working on it? If not, I might try to implement it as it's blocking some stuff I am trying to build.

@azf20
Copy link
Contributor

azf20 commented Aug 9, 2023

hey @Preston-Harrison I think @saihaj was looking at Matchstick, but this isn't currently being worked on, would be great if you might be able to help?

@kevandee
Copy link

Hi @Preston-Harrison, I agree with @azf20. I also think that they are not currently working on it. I need your help too)

@mffrench
Copy link

mffrench commented Mar 15, 2024

Hello,

still getting that issue with following dependencies:

    "dependencies": {
        "@graphprotocol/graph-cli": "0.68.5",
        "@graphprotocol/graph-ts": "0.33.0"
    },
    "devDependencies": {
        "matchstick-as": "0.6.0"
    }

this is blocking if I keep our smart contract event unchanged. But if I change them, I do only cause previous The Graph version (graph-cli:0.46.1 ; graph-ts: 0.29.1) are not handling N-M relationships correctly within subgraph logic... A fix on that issue would be consequently much appreciated.

Best,

@dimitrovmaksim
Copy link
Member

loadRelated should be supported in matchstick 0.6.0 and matchstick-as 0.6.0

@mffrench
Copy link

Well just tested with the dependencies I told you - upgraded matchstick-as from 0.5.0 to 0.6.0 for that purpose...

I will retest just to be sure anyway.

Is there a way to display the matchstick version used while testing ?

Thank you

@dimitrovmaksim
Copy link
Member

dimitrovmaksim commented Mar 15, 2024

You can see the version with graph test -- --version
And you can force a specific version with graph test -v 0.6.0
But unless the version is specified it should always use the latest version, which currently is 0.6.0

@mffrench
Copy link

OK, so I confirm matchstick 0.6.0 is solving that 🆘 Could not create WasmInstance from valid module with context: unknown import: index::store.loadRelated has not been defined error. Thank you @dimitrovmaksim .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants