@graphprotocol/graph-cli 0.38.1-alpha-20230208031159-e8f0545 → 0.38.1-alpha-20230208032550-ddc8362
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/codegen.js +38 -61
- package/dist/commands/create.js +1 -1
- package/dist/commands/remove.js +32 -56
- package/oclif.manifest.json +75 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/commands/codegen.js
CHANGED
|
@@ -27,69 +27,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const path_1 = __importDefault(require("path"));
|
|
30
|
-
const
|
|
30
|
+
const core_1 = require("@oclif/core");
|
|
31
31
|
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
32
|
-
const gluegun_1 = require("../command-helpers/gluegun");
|
|
33
32
|
const version_1 = require("../command-helpers/version");
|
|
34
33
|
const debug_1 = __importDefault(require("../debug"));
|
|
35
34
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
36
35
|
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
36
|
const codegenDebug = (0, debug_1.default)('graph-cli:codegen');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 || (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
|
-
[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
|
-
}
|
|
37
|
+
class CodegenCommand extends core_1.Command {
|
|
38
|
+
async run() {
|
|
39
|
+
const { args: { 'subgraph-manifest': manifest }, flags: { 'output-dir': outputDir, 'skip-migrations': skipMigrations, watch, uncrashable, 'uncrashable-config': uncrashableConfig, }, } = await this.parse(CodegenCommand);
|
|
78
40
|
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
41
|
let protocol;
|
|
94
42
|
try {
|
|
95
43
|
// Checks to make sure codegen doesn't run against
|
|
@@ -104,9 +52,7 @@ exports.default = {
|
|
|
104
52
|
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
105
53
|
}
|
|
106
54
|
catch (e) {
|
|
107
|
-
|
|
108
|
-
process.exitCode = 1;
|
|
109
|
-
return;
|
|
55
|
+
this.error(e, { exit: 1 });
|
|
110
56
|
}
|
|
111
57
|
const generator = new type_generator_1.default({
|
|
112
58
|
subgraphManifest: manifest,
|
|
@@ -114,7 +60,7 @@ exports.default = {
|
|
|
114
60
|
skipMigrations,
|
|
115
61
|
protocol,
|
|
116
62
|
uncrashable,
|
|
117
|
-
uncrashableConfig
|
|
63
|
+
uncrashableConfig,
|
|
118
64
|
});
|
|
119
65
|
// Watch working directory for file updates or additions, trigger
|
|
120
66
|
// type generation (if watch argument specified)
|
|
@@ -124,5 +70,36 @@ exports.default = {
|
|
|
124
70
|
else if (!(await generator.generateTypes())) {
|
|
125
71
|
process.exitCode = 1;
|
|
126
72
|
}
|
|
127
|
-
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.default = CodegenCommand;
|
|
76
|
+
CodegenCommand.description = 'Generates AssemblyScript types for a subgraph.';
|
|
77
|
+
CodegenCommand.args = {
|
|
78
|
+
'subgraph-manifest': core_1.Args.string({
|
|
79
|
+
required: true,
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
CodegenCommand.flags = {
|
|
83
|
+
'output-dir': core_1.Flags.string({
|
|
84
|
+
summary: 'Output directory for generated types.',
|
|
85
|
+
char: 'o',
|
|
86
|
+
default: 'generated/',
|
|
87
|
+
}),
|
|
88
|
+
'skip-migrations': core_1.Flags.boolean({
|
|
89
|
+
summary: 'Skip subgraph migrations.',
|
|
90
|
+
}),
|
|
91
|
+
watch: core_1.Flags.boolean({
|
|
92
|
+
summary: 'Regenerate types when subgraph files change.',
|
|
93
|
+
char: 'w',
|
|
94
|
+
}),
|
|
95
|
+
uncrashable: core_1.Flags.boolean({
|
|
96
|
+
summary: 'Generate Float Subgraph Uncrashable helper file.',
|
|
97
|
+
char: 'u',
|
|
98
|
+
}),
|
|
99
|
+
'uncrashable-config': core_1.Flags.string({
|
|
100
|
+
summary: 'Directory for uncrashable config.',
|
|
101
|
+
aliases: ['uc'],
|
|
102
|
+
default: 'uncrashable-config.yaml',
|
|
103
|
+
dependsOn: ['uncrashable'],
|
|
104
|
+
}),
|
|
128
105
|
};
|
package/dist/commands/create.js
CHANGED
package/dist/commands/remove.js
CHANGED
|
@@ -1,74 +1,33 @@
|
|
|
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: 'Unregisters 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
|
-
help || (help = h);
|
|
30
|
-
node || (node = g);
|
|
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 RemoveCommand extends core_1.Command {
|
|
9
|
+
async run() {
|
|
10
|
+
const { args: { 'subgraph-name': subgraphName }, flags: { 'access-token': accessTokenFlag, node }, } = await this.parse(RemoveCommand);
|
|
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);
|
|
60
19
|
// Exit with an error code if the client couldn't be created
|
|
61
20
|
if (!client) {
|
|
62
|
-
|
|
21
|
+
this.exit(1);
|
|
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(`Removing subgraph in Graph node: ${requestUrl}`);
|
|
72
31
|
client.request('subgraph_remove', { name: subgraphName }, (
|
|
73
32
|
// @ts-expect-error TODO: why are the arguments not typed?
|
|
74
33
|
requestError,
|
|
@@ -79,17 +38,34 @@ exports.default = {
|
|
|
79
38
|
// @ts-expect-error TODO: why are the arguments not typed?
|
|
80
39
|
_res) => {
|
|
81
40
|
if (jsonRpcError) {
|
|
82
|
-
|
|
83
|
-
|
|
41
|
+
core_1.ux.action.stop(`✖ Error removed the subgraph: ${jsonRpcError.message}`);
|
|
42
|
+
this.exit(1);
|
|
84
43
|
}
|
|
85
44
|
else if (requestError) {
|
|
86
|
-
|
|
87
|
-
|
|
45
|
+
core_1.ux.action.stop(`✖ HTTP error removed the subgraph: ${requestError.code}`);
|
|
46
|
+
this.exit(1);
|
|
88
47
|
}
|
|
89
48
|
else {
|
|
90
|
-
|
|
91
|
-
|
|
49
|
+
core_1.ux.action.stop('Subgraph removed');
|
|
50
|
+
this.exit(1);
|
|
92
51
|
}
|
|
93
52
|
});
|
|
94
|
-
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = RemoveCommand;
|
|
56
|
+
RemoveCommand.description = 'Unregisters a subgraph name';
|
|
57
|
+
RemoveCommand.args = {
|
|
58
|
+
'subgraph-name': core_1.Args.string({
|
|
59
|
+
required: true,
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
RemoveCommand.flags = {
|
|
63
|
+
node: core_1.Flags.string({
|
|
64
|
+
summary: 'Graph node to delete the subgraph from.',
|
|
65
|
+
char: 'g',
|
|
66
|
+
required: true,
|
|
67
|
+
}),
|
|
68
|
+
'access-token': core_1.Flags.string({
|
|
69
|
+
summary: 'Graph access token.',
|
|
70
|
+
}),
|
|
95
71
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.38.1-alpha-
|
|
2
|
+
"version": "0.38.1-alpha-20230208032550-ddc8362",
|
|
3
3
|
"commands": {
|
|
4
4
|
"add": {
|
|
5
5
|
"id": "add",
|
|
@@ -132,13 +132,61 @@
|
|
|
132
132
|
},
|
|
133
133
|
"codegen": {
|
|
134
134
|
"id": "codegen",
|
|
135
|
-
"description": "Generates AssemblyScript types for a subgraph",
|
|
135
|
+
"description": "Generates AssemblyScript types for a subgraph.",
|
|
136
|
+
"strict": true,
|
|
136
137
|
"pluginName": "@graphprotocol/graph-cli",
|
|
137
138
|
"pluginAlias": "@graphprotocol/graph-cli",
|
|
138
139
|
"pluginType": "core",
|
|
139
140
|
"aliases": [],
|
|
140
|
-
"flags": {
|
|
141
|
-
|
|
141
|
+
"flags": {
|
|
142
|
+
"output-dir": {
|
|
143
|
+
"name": "output-dir",
|
|
144
|
+
"type": "option",
|
|
145
|
+
"char": "o",
|
|
146
|
+
"summary": "Output directory for generated types.",
|
|
147
|
+
"multiple": false,
|
|
148
|
+
"default": "generated/"
|
|
149
|
+
},
|
|
150
|
+
"skip-migrations": {
|
|
151
|
+
"name": "skip-migrations",
|
|
152
|
+
"type": "boolean",
|
|
153
|
+
"summary": "Skip subgraph migrations.",
|
|
154
|
+
"allowNo": false
|
|
155
|
+
},
|
|
156
|
+
"watch": {
|
|
157
|
+
"name": "watch",
|
|
158
|
+
"type": "boolean",
|
|
159
|
+
"char": "w",
|
|
160
|
+
"summary": "Regenerate types when subgraph files change.",
|
|
161
|
+
"allowNo": false
|
|
162
|
+
},
|
|
163
|
+
"uncrashable": {
|
|
164
|
+
"name": "uncrashable",
|
|
165
|
+
"type": "boolean",
|
|
166
|
+
"char": "u",
|
|
167
|
+
"summary": "Generate Float Subgraph Uncrashable helper file.",
|
|
168
|
+
"allowNo": false
|
|
169
|
+
},
|
|
170
|
+
"uncrashable-config": {
|
|
171
|
+
"name": "uncrashable-config",
|
|
172
|
+
"type": "option",
|
|
173
|
+
"summary": "Directory for uncrashable config.",
|
|
174
|
+
"multiple": false,
|
|
175
|
+
"dependsOn": [
|
|
176
|
+
"uncrashable"
|
|
177
|
+
],
|
|
178
|
+
"default": "uncrashable-config.yaml",
|
|
179
|
+
"aliases": [
|
|
180
|
+
"uc"
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"args": {
|
|
185
|
+
"subgraph-manifest": {
|
|
186
|
+
"name": "subgraph-manifest",
|
|
187
|
+
"required": true
|
|
188
|
+
}
|
|
189
|
+
}
|
|
142
190
|
},
|
|
143
191
|
"create": {
|
|
144
192
|
"id": "create",
|
|
@@ -327,12 +375,33 @@
|
|
|
327
375
|
"remove": {
|
|
328
376
|
"id": "remove",
|
|
329
377
|
"description": "Unregisters a subgraph name",
|
|
378
|
+
"strict": true,
|
|
330
379
|
"pluginName": "@graphprotocol/graph-cli",
|
|
331
380
|
"pluginAlias": "@graphprotocol/graph-cli",
|
|
332
381
|
"pluginType": "core",
|
|
333
382
|
"aliases": [],
|
|
334
|
-
"flags": {
|
|
335
|
-
|
|
383
|
+
"flags": {
|
|
384
|
+
"node": {
|
|
385
|
+
"name": "node",
|
|
386
|
+
"type": "option",
|
|
387
|
+
"char": "g",
|
|
388
|
+
"summary": "Graph node to delete the subgraph from.",
|
|
389
|
+
"required": true,
|
|
390
|
+
"multiple": false
|
|
391
|
+
},
|
|
392
|
+
"access-token": {
|
|
393
|
+
"name": "access-token",
|
|
394
|
+
"type": "option",
|
|
395
|
+
"summary": "Graph access token.",
|
|
396
|
+
"multiple": false
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
"args": {
|
|
400
|
+
"subgraph-name": {
|
|
401
|
+
"name": "subgraph-name",
|
|
402
|
+
"required": true
|
|
403
|
+
}
|
|
404
|
+
}
|
|
336
405
|
},
|
|
337
406
|
"test": {
|
|
338
407
|
"id": "test",
|
package/package.json
CHANGED