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