@graphprotocol/graph-cli 0.38.1-alpha-20230208030436-e93ce80 → 0.38.1-alpha-20230208031159-e8f0545
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 +1 -1
- package/dist/commands/create.js +31 -55
- package/oclif.manifest.json +24 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/commands/create.js
CHANGED
|
@@ -1,59 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
const url_1 = require("url");
|
|
7
|
-
const
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
8
5
|
const auth_1 = require("../command-helpers/auth");
|
|
9
6
|
const jsonrpc_1 = require("../command-helpers/jsonrpc");
|
|
10
7
|
const node_1 = require("../command-helpers/node");
|
|
11
|
-
|
|
12
|
-
|
|
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 || (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
|
-
}
|
|
8
|
+
class CreateCommand extends core_1.Command {
|
|
9
|
+
async run() {
|
|
10
|
+
const { args: { 'subgraph-name': subgraphName }, flags: { 'access-token': accessTokenFlag, node }, } = await this.parse(CreateCommand);
|
|
50
11
|
try {
|
|
51
12
|
(0, node_1.validateNodeUrl)(node);
|
|
52
13
|
}
|
|
53
14
|
catch (e) {
|
|
54
|
-
|
|
55
|
-
process.exitCode = 1;
|
|
56
|
-
return;
|
|
15
|
+
this.error(`Graph node "${node}" is invalid: ${e.message}`, { exit: 1 });
|
|
57
16
|
}
|
|
58
17
|
const requestUrl = new url_1.URL(node);
|
|
59
18
|
const client = (0, jsonrpc_1.createJsonRpcClient)(requestUrl);
|
|
@@ -63,12 +22,12 @@ exports.default = {
|
|
|
63
22
|
return;
|
|
64
23
|
}
|
|
65
24
|
// Use the access token, if one is set
|
|
66
|
-
accessToken = await (0, auth_1.identifyDeployKey)(node,
|
|
25
|
+
const accessToken = await (0, auth_1.identifyDeployKey)(node, accessTokenFlag);
|
|
67
26
|
if (accessToken !== undefined && accessToken !== null) {
|
|
68
27
|
// @ts-expect-error options property seems to exist
|
|
69
28
|
client.options.headers = { Authorization: `Bearer ${accessToken}` };
|
|
70
29
|
}
|
|
71
|
-
|
|
30
|
+
core_1.ux.action.start(`Creating subgraph in Graph node: ${requestUrl}`);
|
|
72
31
|
client.request('subgraph_create', { name: subgraphName }, (
|
|
73
32
|
// @ts-expect-error TODO: why are the arguments not typed?
|
|
74
33
|
requestError,
|
|
@@ -78,17 +37,34 @@ exports.default = {
|
|
|
78
37
|
// @ts-expect-error TODO: why are the arguments not typed?
|
|
79
38
|
_res) => {
|
|
80
39
|
if (jsonRpcError) {
|
|
81
|
-
|
|
82
|
-
|
|
40
|
+
core_1.ux.action.stop(`✖ Error creating the subgraph: ${jsonRpcError.message}`);
|
|
41
|
+
this.exit(1);
|
|
83
42
|
}
|
|
84
43
|
else if (requestError) {
|
|
85
|
-
|
|
86
|
-
|
|
44
|
+
core_1.ux.action.stop(`✖ HTTP error creating the subgraph: ${requestError.code}`);
|
|
45
|
+
this.exit(1);
|
|
87
46
|
}
|
|
88
47
|
else {
|
|
89
|
-
|
|
90
|
-
|
|
48
|
+
core_1.ux.action.stop();
|
|
49
|
+
this.exit(1);
|
|
91
50
|
}
|
|
92
51
|
});
|
|
93
|
-
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = CreateCommand;
|
|
55
|
+
CreateCommand.description = 'Registers a subgraph name';
|
|
56
|
+
CreateCommand.args = {
|
|
57
|
+
'subgraph-name': core_1.Args.string({
|
|
58
|
+
required: true,
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
CreateCommand.flags = {
|
|
62
|
+
node: core_1.Flags.string({
|
|
63
|
+
summary: 'Graph node to create the subgraph in.',
|
|
64
|
+
char: 'g',
|
|
65
|
+
required: true,
|
|
66
|
+
}),
|
|
67
|
+
'access-token': core_1.Flags.string({
|
|
68
|
+
summary: 'Graph access token.',
|
|
69
|
+
}),
|
|
94
70
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.38.1-alpha-
|
|
2
|
+
"version": "0.38.1-alpha-20230208031159-e8f0545",
|
|
3
3
|
"commands": {
|
|
4
4
|
"add": {
|
|
5
5
|
"id": "add",
|
|
@@ -143,12 +143,33 @@
|
|
|
143
143
|
"create": {
|
|
144
144
|
"id": "create",
|
|
145
145
|
"description": "Registers a subgraph name",
|
|
146
|
+
"strict": true,
|
|
146
147
|
"pluginName": "@graphprotocol/graph-cli",
|
|
147
148
|
"pluginAlias": "@graphprotocol/graph-cli",
|
|
148
149
|
"pluginType": "core",
|
|
149
150
|
"aliases": [],
|
|
150
|
-
"flags": {
|
|
151
|
-
|
|
151
|
+
"flags": {
|
|
152
|
+
"node": {
|
|
153
|
+
"name": "node",
|
|
154
|
+
"type": "option",
|
|
155
|
+
"char": "g",
|
|
156
|
+
"summary": "Graph node to create the subgraph in.",
|
|
157
|
+
"required": true,
|
|
158
|
+
"multiple": false
|
|
159
|
+
},
|
|
160
|
+
"access-token": {
|
|
161
|
+
"name": "access-token",
|
|
162
|
+
"type": "option",
|
|
163
|
+
"summary": "Graph access token.",
|
|
164
|
+
"multiple": false
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
"args": {
|
|
168
|
+
"subgraph-name": {
|
|
169
|
+
"name": "subgraph-name",
|
|
170
|
+
"required": true
|
|
171
|
+
}
|
|
172
|
+
}
|
|
152
173
|
},
|
|
153
174
|
"deploy": {
|
|
154
175
|
"id": "deploy",
|
package/package.json
CHANGED