graph-tooling icon indicating copy to clipboard operation
graph-tooling copied to clipboard

Importing using wildcard export causes `UNCAUGHT EXCEPTION`

Open undermethod opened this issue 3 years ago • 4 comments

  1. root git dir contains (among others) /src/constants/ dir, itself containing:
    • sampleconst.ts:
      export const STR_HARDCODED = "StrVal";
      
      along with index.ts:
      export * from "sampleconst.ts";
      
  2. child dir /subgraph/ contains (among others):
    • package.json
      • "@graphprotocol/graph-cli": "^0.29.0",
      • "@graphprotocol/graph-ts": "^0.26.0",
    • schema, manifest, lock file, locally installed dependencies
    • /src/ (among others) contains:
      • mappings/samplemapping.ts containing
        import { Sample as SampleEvent } from "../../generated/SampleContractName/SampleContract";
        import { SampleEntity } from "../../generated/schema";
        import { STR_HARDCODED } from "../../../src/constants"; // <-- issue is here
        
        export function handleSampleEvent(event: SampleEvent): void {
          const entity = new Entity(event.transaction.hash.toHex());
          entity.role = STR_HARDCODED;
          entity.save();
        }
        
  3. performing a codegen succeeds
  4. performing a build fails:
    Error: Failed to compile data source mapping: assertion failed
        at Compiler._compileDataSourceMapping (/Users/path/subgraph/node_modules/@graphprotocol/graph-cli/src/compiler/index.js:307:13)
        at /Users/path/subgraph/node_modules/@graphprotocol/graph-cli/src/compiler/index.js:216:20
        at updateInDeepMap (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1971:22)
        at updateInDeepMap (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1980:23)
        at updateInDeepMap (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1980:23)
        at Map.updateIn (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:1278:26)
        at /Users/path/subgraph/node_modules/@graphprotocol/graph-cli/src/compiler/index.js:215:24
        at /Users/path/subgraph/node_modules/immutable/dist/immutable.js:3016:46
        at List.__iterate (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:2206:13)
        at IndexedIterable.mappedSequence.__iterateUncached (/Users/path/subgraph/node_modules/immutable/dist/immutable.js:3015:23)
    UNCAUGHT EXCEPTION: Error: The AssemblyScript compiler crashed when compiling this file: 'src/mappings/samplemapping.ts'
    Suggestion: try to comment the whole file and uncomment it little by little while re-running the graph-cli until you isolate the line where the problem happens.
    Also, please contact us so we can make the CLI better by handling errors like this. You can reach out in any of these links:
    - Discord channel: https://discord.gg/eM8CA6WA9r
    - Github issues: https://github.com/graphprotocol/graph-cli/issues
    error Command failed with exit code 1.
    
  5. simply commenting out the above import and replacing with the hardcoded string itself:
    import { Sample as SampleEvent } from "../../generated/SampleContractName/SampleContract";
    import { SampleEntity } from "../../generated/schema";
    // import { STR_HARDCODED } from "../../../src/constants"; // <-- no longer import from dir parent to subgraph
    
    export function handleSampleEvent(event: SampleEvent): void {
      const entity = new Entity(event.transaction.hash.toHex());
      entity.role = "StrVal"; // replaced with raw hardcoded string no longer imported
      entity.save();
    }
    
  6. both codegen and build succeed

Let me know if any other info would help.

undermethod avatar Apr 22 '22 22:04 undermethod

Hi! I don't know if wildcard exports are supported by Assemblyscript? https://github.com/AssemblyScript/assemblyscript/issues/27 cc @evaporei

azf20 avatar Apr 25 '22 11:04 azf20

wildcard exports

Good call! Simply updating to the non-indexed path worked:

import { Sample as SampleEvent } from "../../generated/SampleContractName/SampleContract";
import { SampleEntity } from "../../generated/schema";
import { STR_HARDCODED } from "../../../src/constants/sampleconst"; // <-- added path to avoid wildcard

export function handleSampleEvent(event: SampleEvent): void {
  const entity = new Entity(event.transaction.hash.toHex());
  entity.role = STR_HARDCODED; // <-- now able to reference without error
  entity.save();
}

I've renamed the issue accordingly.

undermethod avatar Apr 25 '22 15:04 undermethod

Wildcard exports are supported by the latest version of AssemblyScript, as well as the @graphprotocol packages.

So I think this issue should be closed now?

PaulRBerg avatar May 11 '25 07:05 PaulRBerg

I noticed a strange behavior whereby files with nested export * from make the Graph Node to not be able to find the handler functions:

function handleCreateMerkleLL not found

But if I have only file that uses export * from, then it works.

PaulRBerg avatar May 31 '25 13:05 PaulRBerg