@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/babel.config.js +3 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +32 -0
- package/dist/codegen/schema.js +250 -0
- package/dist/codegen/schema.test.js +458 -0
- package/dist/codegen/template.js +65 -0
- package/dist/codegen/types/conversions.js +359 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +46 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +78 -0
- package/dist/command-helpers/auth.js +77 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +49 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +29 -0
- package/dist/command-helpers/network.js +93 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +112 -0
- package/dist/command-helpers/spinner.js +84 -0
- package/dist/command-helpers/studio.js +13 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +24 -0
- package/dist/command-helpers/version.js +74 -0
- package/dist/command-helpers/version.test.js +179 -0
- package/dist/commands/add.js +190 -0
- package/dist/commands/auth.js +127 -0
- package/dist/commands/build.js +140 -0
- package/dist/commands/codegen.js +135 -0
- package/dist/commands/create.js +86 -0
- package/dist/commands/deploy.js +334 -0
- package/dist/commands/init.js +788 -0
- package/dist/commands/local.js +387 -0
- package/dist/commands/remove.js +86 -0
- package/dist/commands/test.js +295 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +474 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
- package/dist/migrations/spec_version_0_0_2.js +49 -0
- package/dist/migrations/spec_version_0_0_3.js +54 -0
- package/dist/migrations/util/load-manifest.js +18 -0
- package/dist/migrations/util/versions.js +29 -0
- package/dist/migrations.js +56 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +25 -0
- package/dist/protocols/ethereum/abi.js +140 -0
- package/dist/protocols/ethereum/codegen/abi.js +451 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
- package/dist/protocols/ethereum/codegen/template.js +50 -0
- package/dist/protocols/ethereum/contract.js +20 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +171 -0
- package/dist/protocols/ethereum/type-generator.js +125 -0
- package/dist/protocols/index.js +268 -0
- package/dist/protocols/ipfs/codegen/file_template.js +50 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +20 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +83 -0
- package/dist/scaffold/ethereum.test.js +505 -0
- package/dist/scaffold/index.js +128 -0
- package/dist/scaffold/mapping.js +61 -0
- package/dist/scaffold/near.test.js +86 -0
- package/dist/scaffold/schema.js +83 -0
- package/dist/scaffold/tests.js +175 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +249 -0
- package/dist/type-generator.js +224 -0
- package/dist/validation/contract.js +46 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/manifest.js +271 -0
- package/dist/validation/schema.js +796 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/jest.config.js +1 -1
- package/package.json +16 -9
- package/{bin/graph → src/bin.ts} +2 -1
- package/src/cli.ts +36 -0
- package/src/codegen/schema.js +23 -22
- package/src/codegen/schema.test.js +33 -27
- package/src/codegen/{template.js → template.ts} +8 -6
- package/src/codegen/types/conversions.ts +382 -0
- package/src/codegen/types/index.js +4 -7
- package/src/codegen/types/index.test.js +10 -4
- package/src/codegen/{typescript.js → typescript.ts} +44 -26
- package/src/codegen/util.js +1 -1
- package/src/codegen/util.test.js +5 -2
- package/src/command-helpers/abi.js +46 -30
- package/src/command-helpers/auth.js +6 -9
- package/src/command-helpers/compiler.js +4 -6
- package/src/command-helpers/data-sources.js +8 -11
- package/src/command-helpers/fs.ts +5 -0
- package/src/command-helpers/gluegun.js +2 -4
- package/src/command-helpers/ipfs.ts +3 -0
- package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
- package/src/command-helpers/network.js +58 -44
- package/src/command-helpers/network.test.js +23 -19
- package/src/command-helpers/node.js +3 -7
- package/src/command-helpers/scaffold.js +34 -25
- package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
- package/src/command-helpers/studio.test.js +61 -30
- package/src/command-helpers/studio.ts +20 -0
- package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
- package/src/command-helpers/version.js +11 -16
- package/src/command-helpers/version.test.js +111 -82
- package/src/commands/add.js +49 -35
- package/src/commands/auth.js +13 -25
- package/src/commands/build.js +9 -9
- package/src/commands/codegen.js +12 -12
- package/src/commands/create.js +22 -22
- package/src/commands/deploy.js +39 -34
- package/src/commands/init.js +21 -24
- package/src/commands/local.js +15 -14
- package/src/commands/remove.js +22 -22
- package/src/commands/test.js +86 -70
- package/src/compiler/{asc.js → asc.ts} +29 -16
- package/src/compiler/index.js +18 -18
- package/src/{debug.js → debug.ts} +2 -2
- package/src/migrations/mapping_api_version_0_0_1.js +7 -7
- package/src/migrations/mapping_api_version_0_0_2.js +5 -5
- package/src/migrations/mapping_api_version_0_0_3.js +7 -7
- package/src/migrations/mapping_api_version_0_0_4.js +7 -7
- package/src/migrations/mapping_api_version_0_0_5.js +7 -7
- package/src/migrations/spec_version_0_0_2.js +5 -5
- package/src/migrations/spec_version_0_0_3.js +5 -5
- package/src/migrations/util/load-manifest.js +6 -9
- package/src/migrations/util/versions.js +5 -10
- package/src/{migrations.js → migrations.ts} +14 -15
- package/src/protocols/arweave/scaffold/manifest.js +1 -4
- package/src/protocols/arweave/scaffold/mapping.js +1 -3
- package/src/protocols/arweave/subgraph.ts +22 -0
- package/src/protocols/cosmos/scaffold/manifest.js +1 -4
- package/src/protocols/cosmos/scaffold/mapping.js +1 -3
- package/src/protocols/cosmos/subgraph.js +2 -2
- package/src/protocols/ethereum/abi.js +7 -13
- package/src/protocols/ethereum/codegen/abi.js +219 -222
- package/src/protocols/ethereum/codegen/abi.test.js +6 -6
- package/src/protocols/ethereum/codegen/template.js +3 -5
- package/src/protocols/ethereum/contract.js +3 -2
- package/src/protocols/ethereum/scaffold/manifest.js +4 -7
- package/src/protocols/ethereum/scaffold/mapping.js +4 -11
- package/src/protocols/ethereum/subgraph.js +21 -20
- package/src/protocols/ethereum/type-generator.js +24 -30
- package/src/protocols/{index.js → index.ts} +65 -46
- package/src/protocols/ipfs/codegen/file_template.js +2 -2
- package/src/protocols/near/{contract.js → contract.ts} +16 -12
- package/src/protocols/near/scaffold/manifest.js +2 -5
- package/src/protocols/near/scaffold/mapping.js +1 -3
- package/src/protocols/near/subgraph.js +3 -6
- package/src/protocols/subgraph.ts +12 -0
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/scaffold/cosmos.test.js +3 -3
- package/src/scaffold/ethereum.test.js +4 -4
- package/src/scaffold/index.js +7 -7
- package/src/scaffold/mapping.js +3 -3
- package/src/scaffold/near.test.js +3 -3
- package/src/scaffold/schema.js +4 -4
- package/src/scaffold/tests.js +72 -58
- package/src/schema.ts +26 -0
- package/src/{subgraph.js → subgraph.ts} +80 -60
- package/src/type-generator.js +20 -20
- package/src/validation/contract.js +2 -6
- package/src/validation/index.js +1 -1
- package/src/validation/manifest.js +24 -22
- package/src/validation/schema.test.js +1 -1
- package/src/validation/{schema.js → schema.ts} +268 -221
- package/src/{watcher.js → watcher.ts} +23 -12
- package/tests/cli/globalSetup.js +2 -2
- package/tests/cli/globalTeardown.js +2 -2
- package/tests/cli/init.test.js +2 -2
- package/tests/cli/util.js +7 -13
- package/tsconfig.json +18 -0
- package/src/cli.js +0 -38
- package/src/codegen/types/conversions.js +0 -329
- package/src/command-helpers/fs.js +0 -8
- package/src/command-helpers/ipfs.js +0 -6
- package/src/command-helpers/studio.js +0 -15
- package/src/protocols/arweave/subgraph.js +0 -20
- package/src/protocols/substreams/subgraph.js +0 -17
- package/src/schema.js +0 -23
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const type_generator_1 = __importDefault(require("../type-generator"));
|
|
32
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
33
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
34
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
35
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
36
|
+
const version_1 = require("../command-helpers/version");
|
|
37
|
+
const HELP = `
|
|
38
|
+
${chalk_1.default.bold('graph codegen')} [options] ${chalk_1.default.bold('[<subgraph-manifest>]')}
|
|
39
|
+
Options:
|
|
40
|
+
-h, --help Show usage information
|
|
41
|
+
-o, --output-dir <path> Output directory for generated types (default: generated/)
|
|
42
|
+
--skip-migrations Skip subgraph migrations (default: false)
|
|
43
|
+
-w, --watch Regenerate types when subgraph files change (default: false)
|
|
44
|
+
-u, --uncrashable Generate Float Subgraph Uncrashable helper file
|
|
45
|
+
-uc, --uncrashable-config <path> Directory for uncrashable config (default: ./uncrashable-config.yaml)
|
|
46
|
+
`;
|
|
47
|
+
let codegenDebug = (0, debug_1.default)('graph-cli:codegen');
|
|
48
|
+
exports.default = {
|
|
49
|
+
description: 'Generates AssemblyScript types for a subgraph',
|
|
50
|
+
run: async (toolbox) => {
|
|
51
|
+
// Obtain tools
|
|
52
|
+
let { filesystem, print, system } = toolbox;
|
|
53
|
+
// Read CLI parameters
|
|
54
|
+
let { h, help, o, outputDir, skipMigrations, w, watch, u, uncrashable, uc, uncrashableConfig, } = toolbox.parameters.options;
|
|
55
|
+
// Support both long and short option variants
|
|
56
|
+
help = help || h;
|
|
57
|
+
outputDir = outputDir || o;
|
|
58
|
+
watch = watch || w;
|
|
59
|
+
uncrashable = uncrashable || u;
|
|
60
|
+
let uncrashable_config = uncrashableConfig || uc;
|
|
61
|
+
let manifest;
|
|
62
|
+
try {
|
|
63
|
+
;
|
|
64
|
+
[manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
65
|
+
h,
|
|
66
|
+
help,
|
|
67
|
+
skipMigrations,
|
|
68
|
+
w,
|
|
69
|
+
watch,
|
|
70
|
+
u,
|
|
71
|
+
uncrashable,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
print.error(e.message);
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
codegenDebug('Initialized codegen manifest: %o', manifest);
|
|
80
|
+
// Fall back to default values for options / parameters
|
|
81
|
+
outputDir =
|
|
82
|
+
outputDir !== undefined && outputDir !== ''
|
|
83
|
+
? outputDir
|
|
84
|
+
: filesystem.path('generated');
|
|
85
|
+
manifest =
|
|
86
|
+
manifest !== undefined && manifest !== ''
|
|
87
|
+
? manifest
|
|
88
|
+
: filesystem.resolve('subgraph.yaml');
|
|
89
|
+
uncrashable_config =
|
|
90
|
+
uncrashable_config !== undefined && uncrashable_config !== ''
|
|
91
|
+
? uncrashable_config
|
|
92
|
+
: filesystem.resolve('uncrashable-config.yaml');
|
|
93
|
+
// Show help text if requested
|
|
94
|
+
if (help) {
|
|
95
|
+
print.info(HELP);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
let protocol;
|
|
99
|
+
try {
|
|
100
|
+
// Checks to make sure codegen doesn't run against
|
|
101
|
+
// older subgraphs (both apiVersion and graph-ts version).
|
|
102
|
+
//
|
|
103
|
+
// We don't want codegen to run without these conditions
|
|
104
|
+
// because that would mean the CLI would generate code to
|
|
105
|
+
// the wrong AssemblyScript version.
|
|
106
|
+
await (0, version_1.assertManifestApiVersion)(manifest, '0.0.5');
|
|
107
|
+
await (0, version_1.assertGraphTsVersion)(path_1.default.dirname(manifest), '0.25.0');
|
|
108
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
109
|
+
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
print.error(e.message);
|
|
113
|
+
process.exitCode = 1;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let generator = new type_generator_1.default({
|
|
117
|
+
subgraphManifest: manifest,
|
|
118
|
+
outputDir: outputDir,
|
|
119
|
+
skipMigrations,
|
|
120
|
+
protocol,
|
|
121
|
+
uncrashable,
|
|
122
|
+
uncrashableConfig: uncrashable_config,
|
|
123
|
+
});
|
|
124
|
+
// Watch working directory for file updates or additions, trigger
|
|
125
|
+
// type generation (if watch argument specified)
|
|
126
|
+
if (watch) {
|
|
127
|
+
await generator.watchAndGenerateTypes();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
if (!(await generator.generateTypes())) {
|
|
131
|
+
process.exitCode = 1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const node_1 = require("../command-helpers/node");
|
|
9
|
+
const auth_1 = require("../command-helpers/auth");
|
|
10
|
+
const jsonrpc_1 = require("../command-helpers/jsonrpc");
|
|
11
|
+
const HELP = `
|
|
12
|
+
${chalk_1.default.bold('graph create')} ${chalk_1.default.dim('[options]')} ${chalk_1.default.bold('<subgraph-name>')}
|
|
13
|
+
|
|
14
|
+
${chalk_1.default.dim('Options:')}
|
|
15
|
+
|
|
16
|
+
--access-token <token> Graph access token
|
|
17
|
+
-h, --help Show usage information
|
|
18
|
+
-g, --node <url> Graph node to create the subgraph in
|
|
19
|
+
`;
|
|
20
|
+
exports.default = {
|
|
21
|
+
description: 'Registers a subgraph name',
|
|
22
|
+
run: async (toolbox) => {
|
|
23
|
+
// Obtain tools
|
|
24
|
+
let { filesystem, print, system } = toolbox;
|
|
25
|
+
// Read CLI parameters
|
|
26
|
+
let { accessToken, g, h, help, node } = toolbox.parameters.options;
|
|
27
|
+
let subgraphName = toolbox.parameters.first;
|
|
28
|
+
// Support both long and short option variants
|
|
29
|
+
node = node || g;
|
|
30
|
+
help = help || h;
|
|
31
|
+
// Show help text if requested
|
|
32
|
+
if (help) {
|
|
33
|
+
print.info(HELP);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Validate the subgraph name
|
|
37
|
+
if (!subgraphName) {
|
|
38
|
+
print.error('No subgraph name provided');
|
|
39
|
+
print.info(HELP);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Validate node
|
|
44
|
+
if (!node) {
|
|
45
|
+
print.error(`No Graph node provided`);
|
|
46
|
+
print.info(HELP);
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
(0, node_1.validateNodeUrl)(node);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
print.error(`Graph node "${node}" is invalid: ${e.message}`);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let requestUrl = new url_1.URL(node);
|
|
59
|
+
let client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
|
|
60
|
+
// Exit with an error code if the client couldn't be created
|
|
61
|
+
if (!client) {
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// Use the access token, if one is set
|
|
66
|
+
accessToken = await (0, auth_1.identifyDeployKey)(node, accessToken);
|
|
67
|
+
if (accessToken !== undefined && accessToken !== null) {
|
|
68
|
+
client.options.headers = { Authorization: `Bearer ${accessToken}` };
|
|
69
|
+
}
|
|
70
|
+
let spinner = print.spin(`Creating subgraph in Graph node: ${requestUrl}`);
|
|
71
|
+
client.request('subgraph_create', { name: subgraphName }, function (requestError, jsonRpcError, res) {
|
|
72
|
+
if (jsonRpcError) {
|
|
73
|
+
spinner.fail(`Error creating the subgraph: ${jsonRpcError.message}`);
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
}
|
|
76
|
+
else if (requestError) {
|
|
77
|
+
spinner.fail(`HTTP error creating the subgraph: ${requestError.code}`);
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
spinner.stop();
|
|
82
|
+
print.success(`Created subgraph: ${subgraphName}`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
};
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const URL = require('url').URL;
|
|
30
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const auth_1 = require("../command-helpers/auth");
|
|
33
|
+
const compiler_1 = require("../command-helpers/compiler");
|
|
34
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
35
|
+
const jsonrpc_1 = require("../command-helpers/jsonrpc");
|
|
36
|
+
const node_1 = require("../command-helpers/node");
|
|
37
|
+
const spinner_1 = require("../command-helpers/spinner");
|
|
38
|
+
const subgraph_1 = require("../command-helpers/subgraph");
|
|
39
|
+
const ipfs_1 = require("../command-helpers/ipfs");
|
|
40
|
+
const version_1 = require("../command-helpers/version");
|
|
41
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
42
|
+
const studio_1 = require("../command-helpers/studio");
|
|
43
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
44
|
+
const network_1 = require("../command-helpers/network");
|
|
45
|
+
const HELP = `
|
|
46
|
+
${chalk_1.default.bold('graph deploy')} [options] ${chalk_1.default.bold('<subgraph-name>')} ${chalk_1.default.bold('[<subgraph-manifest>]')}
|
|
47
|
+
|
|
48
|
+
Options:
|
|
49
|
+
|
|
50
|
+
--product <subgraph-studio|hosted-service>
|
|
51
|
+
Selects the product to which to deploy
|
|
52
|
+
--studio Shortcut for --product subgraph-studio
|
|
53
|
+
-g, --node <node> Graph node to which to deploy
|
|
54
|
+
--deploy-key <key> User deploy key
|
|
55
|
+
-l --version-label <label> Version label used for the deployment
|
|
56
|
+
-h, --help Show usage information
|
|
57
|
+
-i, --ipfs <node> Upload build results to an IPFS node (default: ${ipfs_1.DEFAULT_IPFS_URL})
|
|
58
|
+
-hdr, --headers <map> Add custom headers that will be used by the IPFS HTTP client (default: {})
|
|
59
|
+
--debug-fork ID of a remote subgraph whose store will be GraphQL queried
|
|
60
|
+
-o, --output-dir <path> Output directory for build results (default: build/)
|
|
61
|
+
--skip-migrations Skip subgraph migrations (default: false)
|
|
62
|
+
-w, --watch Regenerate types when subgraph files change (default: false)
|
|
63
|
+
--network <name> Network configuration to use from the networks config file
|
|
64
|
+
--network-file <path> Networks config file path (default: "./networks.json")
|
|
65
|
+
`;
|
|
66
|
+
const processForm = async (toolbox, { product, studio, node, versionLabel }) => {
|
|
67
|
+
const questions = [
|
|
68
|
+
{
|
|
69
|
+
type: 'select',
|
|
70
|
+
name: 'product',
|
|
71
|
+
message: 'Product for which to deploy',
|
|
72
|
+
choices: ['subgraph-studio', 'hosted-service'],
|
|
73
|
+
skip: product === 'subgraph-studio' ||
|
|
74
|
+
product === 'hosted-service' ||
|
|
75
|
+
studio !== undefined ||
|
|
76
|
+
node !== undefined,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: 'input',
|
|
80
|
+
name: 'versionLabel',
|
|
81
|
+
message: 'Version Label (e.g. v0.0.1)',
|
|
82
|
+
skip: versionLabel !== undefined,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
try {
|
|
86
|
+
const answers = await toolbox.prompt.ask(questions);
|
|
87
|
+
return answers;
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.default = {
|
|
94
|
+
description: 'Deploys the subgraph to a Graph node',
|
|
95
|
+
run: async (toolbox) => {
|
|
96
|
+
// Obtain tools
|
|
97
|
+
let { filesystem, print, system } = toolbox;
|
|
98
|
+
// Parse CLI parameters
|
|
99
|
+
let { product, studio, deployKey, accessToken, versionLabel, l, g, h, i, help, ipfs, headers, hdr, node, o, outputDir, skipMigrations, w, watch, debugFork, network, networkFile, } = toolbox.parameters.options;
|
|
100
|
+
// Support both long and short option variants
|
|
101
|
+
help = help || h;
|
|
102
|
+
ipfs = ipfs || i || ipfs_1.DEFAULT_IPFS_URL;
|
|
103
|
+
headers = headers || hdr || '{}';
|
|
104
|
+
node = node || g;
|
|
105
|
+
outputDir = outputDir || o;
|
|
106
|
+
watch = watch || w;
|
|
107
|
+
versionLabel = versionLabel || l;
|
|
108
|
+
try {
|
|
109
|
+
headers = JSON.parse(headers);
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
print.error('Please make sure headers is a valid JSON value');
|
|
113
|
+
process.exitCode = 1;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let subgraphName, manifest;
|
|
117
|
+
try {
|
|
118
|
+
;
|
|
119
|
+
[subgraphName, manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
120
|
+
h,
|
|
121
|
+
help,
|
|
122
|
+
w,
|
|
123
|
+
watch,
|
|
124
|
+
studio,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
print.error(e.message);
|
|
129
|
+
process.exitCode = 1;
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// Fall back to default values for options / parameters
|
|
133
|
+
outputDir = outputDir && outputDir !== '' ? outputDir : filesystem.path('build');
|
|
134
|
+
manifest =
|
|
135
|
+
manifest !== undefined && manifest !== ''
|
|
136
|
+
? manifest
|
|
137
|
+
: filesystem.resolve('subgraph.yaml');
|
|
138
|
+
networkFile =
|
|
139
|
+
networkFile !== undefined && networkFile !== ''
|
|
140
|
+
? networkFile
|
|
141
|
+
: filesystem.resolve('networks.json');
|
|
142
|
+
try {
|
|
143
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
144
|
+
for (const { network } of dataSourcesAndTemplates) {
|
|
145
|
+
(0, studio_1.validateStudioNetwork)({ studio, product, network });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
print.error(e.message);
|
|
150
|
+
process.exitCode = 1;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Show help text if requested
|
|
154
|
+
if (help) {
|
|
155
|
+
print.info(HELP);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
;
|
|
159
|
+
({ node } = (0, node_1.chooseNodeUrl)({ product, studio, node }));
|
|
160
|
+
if (!node) {
|
|
161
|
+
const inputs = await processForm(toolbox, {
|
|
162
|
+
product,
|
|
163
|
+
studio,
|
|
164
|
+
node,
|
|
165
|
+
versionLabel: 'skip', // determine label requirement later
|
|
166
|
+
});
|
|
167
|
+
if (inputs === undefined) {
|
|
168
|
+
process.exit(1);
|
|
169
|
+
}
|
|
170
|
+
product = inputs.product;
|
|
171
|
+
({ node } = (0, node_1.chooseNodeUrl)({
|
|
172
|
+
product,
|
|
173
|
+
studio,
|
|
174
|
+
node,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
// Validate the subgraph name
|
|
178
|
+
if (!subgraphName) {
|
|
179
|
+
print.error(`No subgraph ${product == 'subgraph-studio' || studio ? 'slug' : 'name'} provided`);
|
|
180
|
+
print.info(HELP);
|
|
181
|
+
process.exitCode = 1;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
// Validate node
|
|
185
|
+
if (!node) {
|
|
186
|
+
print.error(`No Graph node provided`);
|
|
187
|
+
print.info(HELP);
|
|
188
|
+
process.exitCode = 1;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Validate IPFS
|
|
192
|
+
if (!ipfs) {
|
|
193
|
+
print.error(`No IPFS node provided`);
|
|
194
|
+
print.info(HELP);
|
|
195
|
+
process.exitCode = 1;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
let protocol;
|
|
199
|
+
try {
|
|
200
|
+
// Checks to make sure deploy doesn't run against
|
|
201
|
+
// older subgraphs (both apiVersion and graph-ts version).
|
|
202
|
+
//
|
|
203
|
+
// We don't want the deploy to run without these conditions
|
|
204
|
+
// because that would mean the CLI would try to compile code
|
|
205
|
+
// using the wrong AssemblyScript compiler.
|
|
206
|
+
await (0, version_1.assertManifestApiVersion)(manifest, '0.0.5');
|
|
207
|
+
await (0, version_1.assertGraphTsVersion)(path_1.default.dirname(manifest), '0.25.0');
|
|
208
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
209
|
+
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
print.error(e.message);
|
|
213
|
+
process.exitCode = 1;
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (network) {
|
|
217
|
+
let identifierName = protocol.getContract().identifierName();
|
|
218
|
+
await (0, network_1.updateSubgraphNetwork)(toolbox, manifest, network, networkFile, identifierName);
|
|
219
|
+
}
|
|
220
|
+
const isStudio = node.match(/studio/);
|
|
221
|
+
const isHostedService = node.match(/thegraph.com/) && !isStudio;
|
|
222
|
+
let compiler = (0, compiler_1.createCompiler)(manifest, {
|
|
223
|
+
ipfs,
|
|
224
|
+
headers,
|
|
225
|
+
outputDir,
|
|
226
|
+
outputFormat: 'wasm',
|
|
227
|
+
skipMigrations,
|
|
228
|
+
blockIpfsMethods: isStudio,
|
|
229
|
+
protocol,
|
|
230
|
+
});
|
|
231
|
+
// Exit with an error code if the compiler couldn't be created
|
|
232
|
+
if (!compiler) {
|
|
233
|
+
process.exitCode = 1;
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
// Ask for label if not on hosted service
|
|
237
|
+
if (!versionLabel && !isHostedService) {
|
|
238
|
+
const inputs = await processForm(toolbox, {
|
|
239
|
+
product,
|
|
240
|
+
studio,
|
|
241
|
+
node,
|
|
242
|
+
versionLabel,
|
|
243
|
+
});
|
|
244
|
+
if (inputs === undefined) {
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
versionLabel = inputs.versionLabel;
|
|
248
|
+
}
|
|
249
|
+
let requestUrl = new URL(node);
|
|
250
|
+
let client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
|
|
251
|
+
// Exit with an error code if the client couldn't be created
|
|
252
|
+
if (!client) {
|
|
253
|
+
process.exitCode = 1;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// Use the deploy key, if one is set
|
|
257
|
+
if (!deployKey && accessToken) {
|
|
258
|
+
deployKey = accessToken; // backwards compatibility
|
|
259
|
+
}
|
|
260
|
+
deployKey = await (0, auth_1.identifyDeployKey)(node, deployKey);
|
|
261
|
+
if (deployKey !== undefined && deployKey !== null) {
|
|
262
|
+
client.options.headers = { Authorization: 'Bearer ' + deployKey };
|
|
263
|
+
}
|
|
264
|
+
let deploySubgraph = async (ipfsHash) => {
|
|
265
|
+
let spinner = print.spin(`Deploying to Graph node ${requestUrl}`);
|
|
266
|
+
// `Failed to deploy to Graph node ${requestUrl}`,
|
|
267
|
+
client.request('subgraph_deploy', {
|
|
268
|
+
name: subgraphName,
|
|
269
|
+
ipfs_hash: ipfsHash,
|
|
270
|
+
version_label: versionLabel,
|
|
271
|
+
debug_fork: debugFork,
|
|
272
|
+
}, async (requestError, jsonRpcError, res) => {
|
|
273
|
+
if (jsonRpcError) {
|
|
274
|
+
spinner.fail(`Failed to deploy to Graph node ${requestUrl}: ${jsonRpcError.message}`);
|
|
275
|
+
// Provide helpful advice when the subgraph has not been created yet
|
|
276
|
+
if (jsonRpcError.message.match(/subgraph name not found/)) {
|
|
277
|
+
if (isHostedService) {
|
|
278
|
+
print.info(`
|
|
279
|
+
You may need to create it at https://thegraph.com/explorer/dashboard.`);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
print.info(`
|
|
283
|
+
Make sure to create the subgraph first by running the following command:
|
|
284
|
+
$ graph create --node ${node} ${subgraphName}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
process.exitCode = 1;
|
|
288
|
+
}
|
|
289
|
+
else if (requestError) {
|
|
290
|
+
spinner.fail(`HTTP error deploying the subgraph ${requestError.code}`);
|
|
291
|
+
process.exitCode = 1;
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
spinner.stop();
|
|
295
|
+
const base = requestUrl.protocol + '//' + requestUrl.hostname;
|
|
296
|
+
let playground = res.playground;
|
|
297
|
+
let queries = res.queries;
|
|
298
|
+
// Add a base URL if graph-node did not return the full URL
|
|
299
|
+
if (playground.charAt(0) === ':') {
|
|
300
|
+
playground = base + playground;
|
|
301
|
+
}
|
|
302
|
+
if (queries.charAt(0) === ':') {
|
|
303
|
+
queries = base + queries;
|
|
304
|
+
}
|
|
305
|
+
if (isHostedService) {
|
|
306
|
+
print.success(`Deployed to ${chalk_1.default.blue(`https://thegraph.com/explorer/subgraph/${subgraphName}`)}`);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
print.success(`Deployed to ${chalk_1.default.blue(`${playground}`)}`);
|
|
310
|
+
}
|
|
311
|
+
print.info('\nSubgraph endpoints:');
|
|
312
|
+
print.info(`Queries (HTTP): ${queries}`);
|
|
313
|
+
print.info(``);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
if (watch) {
|
|
318
|
+
await compiler.watchAndCompile(async (ipfsHash) => {
|
|
319
|
+
if (ipfsHash !== undefined) {
|
|
320
|
+
await deploySubgraph(ipfsHash);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
let result = await compiler.compile();
|
|
326
|
+
if (result === undefined || result === false) {
|
|
327
|
+
// Compilation failed, not deploying.
|
|
328
|
+
process.exitCode = 1;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
await deploySubgraph(result);
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
};
|