@graphprotocol/graph-cli 0.51.2-alpha-20230621172007-4f03cf8 → 0.51.2-alpha-20230621173826-ff8058f
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 +4 -5
- package/dist/commands/init.js +75 -86
- package/dist/type-generator.js +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.51.2-alpha-
|
|
3
|
+
## 0.51.2-alpha-20230621173826-ff8058f
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
8
|
-
[`
|
|
9
|
-
Thanks [@saihaj](https://github.com/saihaj)! -
|
|
10
|
-
`graph init --from-example ...`
|
|
7
|
+
- [#1384](https://github.com/graphprotocol/graph-tooling/pull/1384)
|
|
8
|
+
[`ff8058f`](https://github.com/graphprotocol/graph-tooling/commit/ff8058fff3bf38afe7deeef1a670c626c93242c3)
|
|
9
|
+
Thanks [@saihaj](https://github.com/saihaj)! - do not crash for codegen when it is substreams
|
|
11
10
|
|
|
12
11
|
## 0.51.1
|
|
13
12
|
|
package/dist/commands/init.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -9,6 +32,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
32
|
const core_1 = require("@oclif/core");
|
|
10
33
|
const gluegun_1 = require("gluegun");
|
|
11
34
|
const abi_1 = require("../command-helpers/abi");
|
|
35
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
12
36
|
const network_1 = require("../command-helpers/network");
|
|
13
37
|
const node_1 = require("../command-helpers/node");
|
|
14
38
|
const scaffold_1 = require("../command-helpers/scaffold");
|
|
@@ -54,18 +78,20 @@ class InitCommand extends core_1.Command {
|
|
|
54
78
|
const commands = {
|
|
55
79
|
link: yarn ? 'yarn link @graphprotocol/graph-cli' : 'npm link @graphprotocol/graph-cli',
|
|
56
80
|
install: yarn ? 'yarn' : 'npm install',
|
|
57
|
-
|
|
58
|
-
codegen: yarn ? 'yarn graph codegen' : 'npx graph codegen',
|
|
81
|
+
codegen: yarn ? 'yarn codegen' : 'npm run codegen',
|
|
59
82
|
deploy: yarn ? 'yarn deploy' : 'npm run deploy',
|
|
60
83
|
};
|
|
61
84
|
// If all parameters are provided from the command-line,
|
|
62
85
|
// go straight to creating the subgraph from the example
|
|
63
|
-
if (fromExample && subgraphName && directory) {
|
|
86
|
+
if (fromExample && subgraphName && directory && protocol) {
|
|
64
87
|
await initSubgraphFromExample.bind(this)({
|
|
65
88
|
fromExample,
|
|
66
89
|
allowSimpleName,
|
|
67
90
|
directory,
|
|
68
91
|
subgraphName,
|
|
92
|
+
studio,
|
|
93
|
+
product,
|
|
94
|
+
protocolInstance: new protocols_1.default(protocol),
|
|
69
95
|
}, { commands });
|
|
70
96
|
// Exit with success
|
|
71
97
|
return this.exit(0);
|
|
@@ -123,46 +149,40 @@ class InitCommand extends core_1.Command {
|
|
|
123
149
|
// Exit with success
|
|
124
150
|
return this.exit(0);
|
|
125
151
|
}
|
|
152
|
+
// Otherwise, take the user through the interactive form
|
|
153
|
+
const answers = await processInitForm.bind(this)({
|
|
154
|
+
protocol: protocol,
|
|
155
|
+
product,
|
|
156
|
+
studio,
|
|
157
|
+
node,
|
|
158
|
+
abi,
|
|
159
|
+
abiPath,
|
|
160
|
+
allowSimpleName,
|
|
161
|
+
directory,
|
|
162
|
+
contract: fromContract,
|
|
163
|
+
indexEvents,
|
|
164
|
+
fromExample,
|
|
165
|
+
network,
|
|
166
|
+
subgraphName,
|
|
167
|
+
contractName,
|
|
168
|
+
startBlock,
|
|
169
|
+
spkgPath,
|
|
170
|
+
});
|
|
171
|
+
if (!answers) {
|
|
172
|
+
this.exit(1);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
126
175
|
if (fromExample) {
|
|
127
|
-
const answers = await processFromExampleInitForm.bind(this)({
|
|
128
|
-
allowSimpleName,
|
|
129
|
-
subgraphName,
|
|
130
|
-
directory,
|
|
131
|
-
});
|
|
132
|
-
if (!answers) {
|
|
133
|
-
this.exit(1);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
176
|
await initSubgraphFromExample.bind(this)({
|
|
137
177
|
fromExample,
|
|
138
178
|
subgraphName: answers.subgraphName,
|
|
139
179
|
directory: answers.directory,
|
|
180
|
+
studio: answers.studio,
|
|
181
|
+
product: answers.product,
|
|
182
|
+
protocolInstance: answers.protocolInstance,
|
|
140
183
|
}, { commands });
|
|
141
184
|
}
|
|
142
185
|
else {
|
|
143
|
-
// Otherwise, take the user through the interactive form
|
|
144
|
-
const answers = await processInitForm.bind(this)({
|
|
145
|
-
protocol: protocol,
|
|
146
|
-
product,
|
|
147
|
-
studio,
|
|
148
|
-
node,
|
|
149
|
-
abi,
|
|
150
|
-
abiPath,
|
|
151
|
-
allowSimpleName,
|
|
152
|
-
directory,
|
|
153
|
-
contract: fromContract,
|
|
154
|
-
indexEvents,
|
|
155
|
-
fromExample,
|
|
156
|
-
network,
|
|
157
|
-
subgraphName,
|
|
158
|
-
contractName,
|
|
159
|
-
startBlock,
|
|
160
|
-
spkgPath,
|
|
161
|
-
});
|
|
162
|
-
if (!answers) {
|
|
163
|
-
this.exit(1);
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
186
|
({ node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
|
|
167
187
|
product: answers.product,
|
|
168
188
|
studio: answers.studio,
|
|
@@ -265,51 +285,6 @@ InitCommand.flags = {
|
|
|
265
285
|
}),
|
|
266
286
|
};
|
|
267
287
|
exports.default = InitCommand;
|
|
268
|
-
async function processFromExampleInitForm({ directory: initDirectory, subgraphName: initSubgraphName, allowSimpleName: initAllowSimpleName, }) {
|
|
269
|
-
try {
|
|
270
|
-
const { subgraphName } = await gluegun_1.prompt.ask([
|
|
271
|
-
{
|
|
272
|
-
type: 'input',
|
|
273
|
-
name: 'subgraphName',
|
|
274
|
-
// TODO: is defaulting to studio ok?
|
|
275
|
-
message: () => 'Subgraph slug',
|
|
276
|
-
initial: initSubgraphName,
|
|
277
|
-
validate: name => {
|
|
278
|
-
try {
|
|
279
|
-
(0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
catch (e) {
|
|
283
|
-
return `${e.message}
|
|
284
|
-
|
|
285
|
-
Examples:
|
|
286
|
-
|
|
287
|
-
$ graph init ${os_1.default.userInfo().username}/${name}
|
|
288
|
-
$ graph init ${name} --allow-simple-name`;
|
|
289
|
-
}
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
]);
|
|
293
|
-
const { directory } = await gluegun_1.prompt.ask([
|
|
294
|
-
{
|
|
295
|
-
type: 'input',
|
|
296
|
-
name: 'directory',
|
|
297
|
-
message: 'Directory to create the subgraph in',
|
|
298
|
-
initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
|
|
299
|
-
validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
|
|
300
|
-
? 'Directory already exists'
|
|
301
|
-
: true,
|
|
302
|
-
},
|
|
303
|
-
]);
|
|
304
|
-
return {
|
|
305
|
-
subgraphName,
|
|
306
|
-
directory,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
catch (e) {
|
|
310
|
-
this.error(e, { exit: 1 });
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
288
|
async function processInitForm({ protocol: initProtocol, product: initProduct, studio: initStudio, node: initNode, abi: initAbi, abiPath: initAbiPath, directory: initDirectory, contract: initContract, indexEvents: initIndexEvents, fromExample: initFromExample, network: initNetwork, subgraphName: initSubgraphName, contractName: initContractName, startBlock: initStartBlock, allowSimpleName: initAllowSimpleName, spkgPath: initSpkgPath, }) {
|
|
314
289
|
let abiFromEtherscan = undefined;
|
|
315
290
|
try {
|
|
@@ -647,7 +622,8 @@ Subgraph ${subgraphName} created in ${relativeDir}
|
|
|
647
622
|
|
|
648
623
|
Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
|
|
649
624
|
}
|
|
650
|
-
async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphName, directory, }, { commands, }) {
|
|
625
|
+
async function initSubgraphFromExample({ protocolInstance, fromExample, allowSimpleName, subgraphName, directory, studio, product, }, { commands, }) {
|
|
626
|
+
const isSubstreams = protocolInstance.name === 'substreams';
|
|
651
627
|
// Fail if the subgraph name is invalid
|
|
652
628
|
if (!revalidateSubgraphName.bind(this)(subgraphName, { allowSimpleName })) {
|
|
653
629
|
process.exitCode = 1;
|
|
@@ -687,6 +663,17 @@ async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphN
|
|
|
687
663
|
this.exit(1);
|
|
688
664
|
return;
|
|
689
665
|
}
|
|
666
|
+
try {
|
|
667
|
+
// It doesn't matter if we changed the URL we clone the YAML,
|
|
668
|
+
// we'll check it's network anyway. If it's a studio subgraph we're dealing with.
|
|
669
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(path_1.default.join(directory, 'subgraph.yaml'));
|
|
670
|
+
for (const { network } of dataSourcesAndTemplates) {
|
|
671
|
+
(0, studio_1.validateStudioNetwork)({ studio, product, network });
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
catch (e) {
|
|
675
|
+
this.error(e.message, { exit: 1 });
|
|
676
|
+
}
|
|
690
677
|
const networkConf = await (0, network_1.initNetworksConfig)(directory, 'address');
|
|
691
678
|
if (networkConf !== true) {
|
|
692
679
|
this.exit(1);
|
|
@@ -733,11 +720,13 @@ async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphN
|
|
|
733
720
|
this.exit(1);
|
|
734
721
|
return;
|
|
735
722
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
723
|
+
if (!isSubstreams) {
|
|
724
|
+
// Run code-generation
|
|
725
|
+
const codegen = await runCodegen(directory, commands.codegen);
|
|
726
|
+
if (codegen !== true) {
|
|
727
|
+
this.exit(1);
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
741
730
|
}
|
|
742
731
|
printNextSteps.bind(this)({ subgraphName, directory }, { commands });
|
|
743
732
|
}
|
package/dist/type-generator.js
CHANGED
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED