diff --git a/.changeset/@graphprotocol_graph-cli-1849-dependencies.md b/.changeset/@graphprotocol_graph-cli-1849-dependencies.md new file mode 100644 index 00000000..c6ca5d47 --- /dev/null +++ b/.changeset/@graphprotocol_graph-cli-1849-dependencies.md @@ -0,0 +1,5 @@ +--- +"@graphprotocol/graph-cli": patch +--- +dependencies updates: + - Updated dependency [`assemblyscript@0.19.23` ↗︎](https://www.npmjs.com/package/assemblyscript/v/0.19.23) (from `0.27.31`, in `dependencies`) diff --git a/.changeset/green-islands-wink.md b/.changeset/green-islands-wink.md new file mode 100644 index 00000000..bd2519de --- /dev/null +++ b/.changeset/green-islands-wink.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': minor +--- + +Update all dependencies diff --git a/.changeset/heavy-socks-cross.md b/.changeset/heavy-socks-cross.md new file mode 100644 index 00000000..264ba271 --- /dev/null +++ b/.changeset/heavy-socks-cross.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +Fix `graph add` flag parameters parsing diff --git a/.changeset/new-gorillas-scream.md b/.changeset/new-gorillas-scream.md new file mode 100644 index 00000000..7b3911a7 --- /dev/null +++ b/.changeset/new-gorillas-scream.md @@ -0,0 +1,11 @@ +--- +'@graphprotocol/graph-cli': minor +--- + +- add networks registry support +- improve `graph init` flow + - filter through the networks as you type + - more information about the networks + - remove unnecessary options depending on the selection + - ESC key to go back +- allow specifying ipfs/url for substreams package diff --git a/.changeset/short-keys-boil.md b/.changeset/short-keys-boil.md new file mode 100644 index 00000000..f10fd68f --- /dev/null +++ b/.changeset/short-keys-boil.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +fix bug with clashing \_id field name in schema diff --git a/.changeset/swift-jobs-count.md b/.changeset/swift-jobs-count.md new file mode 100644 index 00000000..d5e790c8 --- /dev/null +++ b/.changeset/swift-jobs-count.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +fix generated example entity id uniqueness diff --git a/.changeset/wet-toys-fry.md b/.changeset/wet-toys-fry.md new file mode 100644 index 00000000..721c3019 --- /dev/null +++ b/.changeset/wet-toys-fry.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +rollback asc version diff --git a/packages/cli/package.json b/packages/cli/package.json index 8b000c64..ce5385a1 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -37,7 +37,7 @@ "@oclif/plugin-warn-if-update-available": "^3.1.24", "@pinax/graph-networks-registry": "^0.6.5", "@whatwg-node/fetch": "^0.10.1", - "assemblyscript": "0.27.31", + "assemblyscript": "0.19.23", "binary-install": "^1.1.0", "chokidar": "4.0.1", "debug": "4.3.7", diff --git a/packages/cli/src/command-helpers/compiler.ts b/packages/cli/src/command-helpers/compiler.ts index eba5fa55..cd684068 100644 --- a/packages/cli/src/command-helpers/compiler.ts +++ b/packages/cli/src/command-helpers/compiler.ts @@ -33,7 +33,7 @@ export function appendApiVersionForGraph(inputString: string) { } // Helper function to construct a subgraph compiler -export async function createCompiler( +export function createCompiler( manifest: string, { ipfs, diff --git a/packages/cli/src/commands/build.ts b/packages/cli/src/commands/build.ts index 1a9ec1b1..9d0f2249 100644 --- a/packages/cli/src/commands/build.ts +++ b/packages/cli/src/commands/build.ts @@ -87,7 +87,7 @@ export default class BuildCommand extends Command { await updateSubgraphNetwork(manifest, network, networkFile, identifierName); } - const compiler = await createCompiler(manifest, { + const compiler = createCompiler(manifest, { ipfs, outputDir, outputFormat, diff --git a/packages/cli/src/commands/deploy.ts b/packages/cli/src/commands/deploy.ts index 94c7556e..91cd9214 100644 --- a/packages/cli/src/commands/deploy.ts +++ b/packages/cli/src/commands/deploy.ts @@ -273,7 +273,7 @@ export default class DeployCommand extends Command { await updateSubgraphNetwork(manifest, network, networkFile, identifierName); } - const compiler = await createCompiler(manifest, { + const compiler = createCompiler(manifest, { ipfs, headers, outputDir, diff --git a/packages/cli/src/commands/publish.ts b/packages/cli/src/commands/publish.ts index 93c09cf0..0eb6e509 100644 --- a/packages/cli/src/commands/publish.ts +++ b/packages/cli/src/commands/publish.ts @@ -145,7 +145,7 @@ export default class PublishCommand extends Command { this.error(e, { exit: 1 }); } - const compiler = await createCompiler(manifest, { + const compiler = createCompiler(manifest, { ipfs, outputDir: 'build/', outputFormat: 'wasm', diff --git a/packages/cli/src/compiler/asc.ts b/packages/cli/src/compiler/asc.ts index 75fe50af..213acff9 100644 --- a/packages/cli/src/compiler/asc.ts +++ b/packages/cli/src/compiler/asc.ts @@ -1,4 +1,4 @@ -import asc from 'assemblyscript/asc'; +import * as asc from 'assemblyscript/cli/asc'; const createExitHandler = (inputFile: string) => () => { throw new Error(`The AssemblyScript compiler crashed when compiling this file: '${inputFile}' @@ -14,14 +14,28 @@ const setupExitHandler = (exitHandler: (code: number) => void) => const removeExitHandler = (exitHandler: (code: number) => void) => process.removeListener('exit', exitHandler); -const assemblyScriptCompiler = async (argv: string[], options: asc.APIOptions) => - await asc.main(argv, options); +// Important note, the `asc.main` callback function parameter is synchronous, +// that's why this function doesn't need to be `async` and the throw works properly. +const assemblyScriptCompiler = (argv: string[], options: asc.APIOptions) => + asc.main(argv, options, err => { + if (err) { + throw err; + } + return 0; + }); const compilerDefaults = { stdout: process.stdout, stderr: process.stdout, }; +// You MUST call this function once before compiling anything. +// Internally it just delegates to the AssemblyScript compiler +// which just delegates to the binaryen lib. +export const ready = async () => { + await asc.ready; +}; + export interface CompileOptions { inputFile: string; global: string; @@ -34,12 +48,13 @@ export interface CompileOptions { // it requires an asynchronous wait. Whenever you call this function, // it doesn't matter how many times, just make sure you call `ready` // once before everything.. -export const compile = async ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => { +export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => { const exitHandler = createExitHandler(inputFile); setupExitHandler(exitHandler); const compilerArgs = [ + '--explicitStart', '--exportRuntime', '--runtime', 'stub', @@ -55,7 +70,7 @@ export const compile = async ({ inputFile, global, baseDir, libs, outputFile }: '--debug', ]; - await assemblyScriptCompiler(compilerArgs, compilerDefaults); + assemblyScriptCompiler(compilerArgs, compilerDefaults); // only if compiler succeeded, that is, when the line above doesn't throw removeExitHandler(exitHandler); diff --git a/packages/cli/src/compiler/index.ts b/packages/cli/src/compiler/index.ts index 77caee5d..6dbe4911 100644 --- a/packages/cli/src/compiler/index.ts +++ b/packages/cli/src/compiler/index.ts @@ -246,41 +246,32 @@ export default class Compiler { // Cache compiled files so identical input files are only compiled once const compiledFiles = new Map(); - // Handle data sources - const dataSources = subgraph.get('dataSources'); - const compiledDataSources = await Promise.all( - dataSources.map(async (dataSource: any) => { - const mappingPath = dataSource.getIn(['mapping', 'file']); - const compiledPath = await this._compileDataSourceMapping( - this.protocol, - dataSource, - mappingPath, - compiledFiles, - spinner, - validate, - ); - return dataSource.setIn(['mapping', 'file'], compiledPath); - }), - ); - subgraph = subgraph.set('dataSources', compiledDataSources); - - // Handle templates if they exist - const templates = subgraph.get('templates'); - if (templates !== undefined) { - const compiledTemplates = await Promise.all( - templates.map(async (template: any) => { - const mappingPath = template.getIn(['mapping', 'file']); - const compiledPath = await this._compileTemplateMapping( - template, + await asc.ready(); + + subgraph = subgraph.update('dataSources', (dataSources: any[]) => + dataSources.map((dataSource: any) => + dataSource.updateIn(['mapping', 'file'], (mappingPath: string) => + this._compileDataSourceMapping( + this.protocol, + dataSource, mappingPath, compiledFiles, spinner, - ); - return template.setIn(['mapping', 'file'], compiledPath); - }), - ); - subgraph = subgraph.set('templates', compiledTemplates); - } + validate, + ), + ), + ), + ); + + subgraph = subgraph.update('templates', (templates: any) => + templates === undefined + ? templates + : templates.map((template: any) => + template.updateIn(['mapping', 'file'], (mappingPath: string) => + this._compileTemplateMapping(template, mappingPath, compiledFiles, spinner), + ), + ), + ); return subgraph; }, @@ -343,7 +334,7 @@ export default class Compiler { return missingHandlers; } - async _compileDataSourceMapping( + _compileDataSourceMapping( protocol: Protocol, dataSource: immutable.Map, mappingPath: string, @@ -397,7 +388,7 @@ export default class Compiler { } const global = path.relative(baseDir, this.globalsFile); - await asc.compile({ + asc.compile({ inputFile, global, baseDir, @@ -424,7 +415,7 @@ export default class Compiler { } } - async _compileTemplateMapping( + _compileTemplateMapping( template: immutable.Collection, mappingPath: string, compiledFiles: Map, @@ -478,7 +469,7 @@ export default class Compiler { } const global = path.relative(baseDir, this.globalsFile); - await asc.compile({ + asc.compile({ inputFile, global, baseDir, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 342cca92..5dc70ea1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -258,8 +258,8 @@ importers: specifier: ^0.10.1 version: 0.10.1 assemblyscript: - specifier: 0.27.31 - version: 0.27.31 + specifier: 0.19.23 + version: 0.19.23 binary-install: specifier: ^1.1.0 version: 1.1.0(debug@4.3.7)