Importing using wildcard export causes `UNCAUGHT EXCEPTION`
- root git dir contains (among others)
/src/constants/dir, itself containing:sampleconst.ts:
along withexport const STR_HARDCODED = "StrVal";index.ts:export * from "sampleconst.ts";
- 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.tscontainingimport { 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(); }
- performing a
codegensucceeds - performing a
buildfails: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. - 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(); } - both
codegenandbuildsucceed
Let me know if any other info would help.
Hi! I don't know if wildcard exports are supported by Assemblyscript? https://github.com/AssemblyScript/assemblyscript/issues/27 cc @evaporei
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.
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?
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.