@graphprotocol/graph-cli 0.49.0-alpha-20230503100511-80612fa → 0.49.0-alpha-20230504000723-2c6e265
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/init.js +190 -197
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/commands/init.js
CHANGED
|
@@ -39,12 +39,10 @@ const scaffold_1 = require("../command-helpers/scaffold");
|
|
|
39
39
|
const spinner_1 = require("../command-helpers/spinner");
|
|
40
40
|
const studio_1 = require("../command-helpers/studio");
|
|
41
41
|
const subgraph_1 = require("../command-helpers/subgraph");
|
|
42
|
-
const debug_1 = __importDefault(require("../debug"));
|
|
43
42
|
const protocols_1 = __importDefault(require("../protocols"));
|
|
44
43
|
const schema_1 = require("../scaffold/schema");
|
|
45
44
|
const validation_1 = require("../validation");
|
|
46
45
|
const add_1 = __importDefault(require("./add"));
|
|
47
|
-
const initDebug = (0, debug_1.default)('graph-cli:init');
|
|
48
46
|
const protocolChoices = Array.from(protocols_1.default.availableProtocols().keys());
|
|
49
47
|
const availableNetworks = protocols_1.default.availableNetworks();
|
|
50
48
|
const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum/gravatar';
|
|
@@ -265,227 +263,222 @@ InitCommand.flags = {
|
|
|
265
263
|
}),
|
|
266
264
|
};
|
|
267
265
|
exports.default = InitCommand;
|
|
268
|
-
async function processInitForm({ protocol, product, studio, node, abi
|
|
266
|
+
async function processInitForm({ protocol: initProtocol, product: initProduct, studio: initStudio, node: initNode, abi: initAbi, directory: initDirectory, contract: initContract, indexEvents: initIndexEvents, fromExample: initFromExample, network: initNetwork, subgraphName: initSubgraphName, contractName: initContractName, startBlock: initStartBlock, allowSimpleName: initAllowSimpleName, }) {
|
|
269
267
|
let abiFromEtherscan = undefined;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
let ProtocolContract;
|
|
273
|
-
let ABI;
|
|
274
|
-
const questions = [
|
|
275
|
-
{
|
|
268
|
+
try {
|
|
269
|
+
const { protocol } = await gluegun_1.prompt.ask({
|
|
276
270
|
type: 'select',
|
|
277
271
|
name: 'protocol',
|
|
278
272
|
message: 'Protocol',
|
|
279
273
|
choices: protocolChoices,
|
|
280
|
-
skip: protocolChoices.includes(String(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
product = value;
|
|
311
|
-
return value;
|
|
274
|
+
skip: protocolChoices.includes(String(initProtocol)),
|
|
275
|
+
});
|
|
276
|
+
const protocolInstance = new protocols_1.default(protocol);
|
|
277
|
+
const { product } = await gluegun_1.prompt.ask([
|
|
278
|
+
{
|
|
279
|
+
type: 'select',
|
|
280
|
+
name: 'product',
|
|
281
|
+
message: 'Product for which to initialize',
|
|
282
|
+
choices: ['subgraph-studio', 'hosted-service'],
|
|
283
|
+
skip: protocol === 'arweave' ||
|
|
284
|
+
protocol === 'cosmos' ||
|
|
285
|
+
protocol === 'near' ||
|
|
286
|
+
initProduct === 'subgraph-studio' ||
|
|
287
|
+
initProduct === 'hosted-service' ||
|
|
288
|
+
initStudio !== undefined ||
|
|
289
|
+
initNode !== undefined,
|
|
290
|
+
result: value => {
|
|
291
|
+
if (initProduct)
|
|
292
|
+
return initProduct;
|
|
293
|
+
if (initStudio)
|
|
294
|
+
return 'subgraph-studio';
|
|
295
|
+
// For now we only support NEAR subgraphs in the Hosted Service
|
|
296
|
+
if (protocol === 'near') {
|
|
297
|
+
return 'hosted-service';
|
|
298
|
+
}
|
|
299
|
+
if (value == 'subgraph-studio') {
|
|
300
|
+
initAllowSimpleName = true;
|
|
301
|
+
}
|
|
302
|
+
return value;
|
|
303
|
+
},
|
|
312
304
|
},
|
|
313
|
-
|
|
314
|
-
{
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
305
|
+
]);
|
|
306
|
+
const { subgraphName } = await gluegun_1.prompt.ask([
|
|
307
|
+
{
|
|
308
|
+
type: 'input',
|
|
309
|
+
name: 'subgraphName',
|
|
310
|
+
message: () => (product == 'subgraph-studio' ? 'Subgraph slug' : 'Subgraph name'),
|
|
311
|
+
initial: initSubgraphName,
|
|
312
|
+
validate: name => {
|
|
313
|
+
try {
|
|
314
|
+
(0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
catch (e) {
|
|
318
|
+
return `${e.message}
|
|
326
319
|
|
|
327
|
-
|
|
320
|
+
Examples:
|
|
328
321
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
322
|
+
$ graph init ${os_1.default.userInfo().username}/${name}
|
|
323
|
+
$ graph init ${name} --allow-simple-name`;
|
|
324
|
+
}
|
|
325
|
+
},
|
|
332
326
|
},
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
327
|
+
]);
|
|
328
|
+
const { directory } = await gluegun_1.prompt.ask([
|
|
329
|
+
{
|
|
330
|
+
type: 'input',
|
|
331
|
+
name: 'directory',
|
|
332
|
+
message: 'Directory to create the subgraph in',
|
|
333
|
+
initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
|
|
334
|
+
validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
|
|
335
|
+
? 'Directory already exists'
|
|
336
|
+
: true,
|
|
336
337
|
},
|
|
337
|
-
|
|
338
|
-
{
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
// @ts-expect-error will be set by previous question
|
|
345
|
-
subgraphName),
|
|
346
|
-
validate: (value) => gluegun_1.filesystem.exists(value ||
|
|
347
|
-
directory ||
|
|
348
|
-
(0, subgraph_1.getSubgraphBasename)(
|
|
349
|
-
// @ts-expect-error will be set by previous question
|
|
350
|
-
subgraphName))
|
|
351
|
-
? 'Directory already exists'
|
|
352
|
-
: true,
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
type: 'select',
|
|
356
|
-
name: 'network',
|
|
357
|
-
message: () => `${protocolInstance.displayName()} network`,
|
|
358
|
-
choices: () => {
|
|
359
|
-
initDebug('Generating list of available networks for protocol "%s" (%M)', protocol, availableNetworks.get(protocol));
|
|
360
|
-
return (
|
|
361
|
-
// @ts-expect-error TODO: wait what?
|
|
362
|
-
availableNetworks
|
|
338
|
+
]);
|
|
339
|
+
const { network } = await gluegun_1.prompt.ask([
|
|
340
|
+
{
|
|
341
|
+
type: 'select',
|
|
342
|
+
name: 'network',
|
|
343
|
+
message: () => `${protocolInstance.displayName()} network`,
|
|
344
|
+
choices: availableNetworks
|
|
363
345
|
.get(protocol) // Get networks related to the chosen protocol.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
network = value;
|
|
370
|
-
return value;
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
// TODO:
|
|
374
|
-
//
|
|
375
|
-
// protocols that don't support contract
|
|
376
|
-
// - arweave
|
|
377
|
-
// - cosmos
|
|
378
|
-
{
|
|
379
|
-
type: 'input',
|
|
380
|
-
name: 'contract',
|
|
381
|
-
message: () => {
|
|
382
|
-
ProtocolContract = protocolInstance.getContract();
|
|
383
|
-
return `Contract ${ProtocolContract.identifierName()}`;
|
|
384
|
-
},
|
|
385
|
-
skip: () => fromExample !== undefined || !protocolInstance.hasContract(),
|
|
386
|
-
initial: contract,
|
|
387
|
-
validate: async (value) => {
|
|
388
|
-
if (fromExample !== undefined || !protocolInstance.hasContract()) {
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
// Validate whether the contract is valid
|
|
392
|
-
const { valid, error } = (0, validation_1.validateContract)(value, ProtocolContract);
|
|
393
|
-
return valid ? true : error;
|
|
394
|
-
},
|
|
395
|
-
result: async (value) => {
|
|
396
|
-
if (fromExample !== undefined) {
|
|
346
|
+
?.toArray() || ['mainnet'],
|
|
347
|
+
skip: initFromExample !== undefined,
|
|
348
|
+
result: value => {
|
|
349
|
+
if (initNetwork)
|
|
350
|
+
return initNetwork;
|
|
397
351
|
return value;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
]);
|
|
355
|
+
const { contract } = await gluegun_1.prompt.ask([
|
|
356
|
+
// TODO:
|
|
357
|
+
// protocols that don't support contract
|
|
358
|
+
// - arweave
|
|
359
|
+
// - cosmos
|
|
360
|
+
{
|
|
361
|
+
type: 'input',
|
|
362
|
+
name: 'contract',
|
|
363
|
+
message: `Contract ${protocolInstance.getContract()?.identifierName()}`,
|
|
364
|
+
skip: () => initFromExample !== undefined || !protocolInstance.hasContract(),
|
|
365
|
+
initial: initContract,
|
|
366
|
+
validate: async (value) => {
|
|
367
|
+
if (initFromExample !== undefined || !protocolInstance.hasContract()) {
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
const protocolContract = protocolInstance.getContract();
|
|
371
|
+
if (!protocolContract) {
|
|
372
|
+
return 'Contract not found.';
|
|
373
|
+
}
|
|
374
|
+
// Validate whether the contract is valid
|
|
375
|
+
const { valid, error } = (0, validation_1.validateContract)(value, protocolContract);
|
|
376
|
+
return valid ? true : error;
|
|
377
|
+
},
|
|
378
|
+
result: async (value) => {
|
|
379
|
+
if (initFromExample !== undefined) {
|
|
380
|
+
return value;
|
|
381
|
+
}
|
|
382
|
+
const ABI = protocolInstance.getABI();
|
|
383
|
+
// Try loading the ABI from Etherscan, if none was provided
|
|
384
|
+
if (protocolInstance.hasABIs() && !initAbi) {
|
|
385
|
+
try {
|
|
386
|
+
if (network === 'poa-core') {
|
|
387
|
+
// TODO: this variable is never used anywhere, what happens?
|
|
388
|
+
// abiFromBlockScout = await loadAbiFromBlockScout(ABI, network, value)
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
abiFromEtherscan = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, value);
|
|
392
|
+
}
|
|
406
393
|
}
|
|
407
|
-
|
|
408
|
-
|
|
394
|
+
catch (e) {
|
|
395
|
+
// noop
|
|
409
396
|
}
|
|
410
397
|
}
|
|
411
|
-
|
|
412
|
-
|
|
398
|
+
// If startBlock is not set, try to load it.
|
|
399
|
+
if (!initStartBlock) {
|
|
400
|
+
try {
|
|
401
|
+
// Load startBlock for this contract
|
|
402
|
+
initStartBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, value)).toString();
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
// noop
|
|
406
|
+
}
|
|
413
407
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
408
|
+
return value;
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
]);
|
|
412
|
+
const { abi: abiFromFile } = await gluegun_1.prompt.ask([
|
|
413
|
+
{
|
|
414
|
+
type: 'input',
|
|
415
|
+
name: 'abi',
|
|
416
|
+
message: 'ABI file (path)',
|
|
417
|
+
initial: initAbi,
|
|
418
|
+
skip: () => !protocolInstance.hasABIs() ||
|
|
419
|
+
initFromExample !== undefined ||
|
|
420
|
+
abiFromEtherscan !== undefined,
|
|
421
|
+
validate: async (value) => {
|
|
422
|
+
if (initFromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
const ABI = protocolInstance.getABI();
|
|
417
426
|
try {
|
|
418
|
-
|
|
419
|
-
startBlock = Number(await (0, abi_1.loadStartBlockForContract)(network, value)).toString();
|
|
427
|
+
return loadAbiFromFile(ABI, value);
|
|
420
428
|
}
|
|
421
|
-
catch (
|
|
422
|
-
|
|
429
|
+
catch (e) {
|
|
430
|
+
return e.message;
|
|
423
431
|
}
|
|
424
|
-
}
|
|
425
|
-
return value;
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
type: 'input',
|
|
430
|
-
name: 'abi',
|
|
431
|
-
message: 'ABI file (path)',
|
|
432
|
-
initial: abi,
|
|
433
|
-
skip: () => !protocolInstance.hasABIs() || fromExample !== undefined || abiFromEtherscan !== undefined,
|
|
434
|
-
validate: async (value) => {
|
|
435
|
-
if (fromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
|
|
436
|
-
return true;
|
|
437
|
-
}
|
|
438
|
-
try {
|
|
439
|
-
abiFromFile = loadAbiFromFile(ABI, value);
|
|
440
|
-
return true;
|
|
441
|
-
}
|
|
442
|
-
catch (e) {
|
|
443
|
-
return e.message;
|
|
444
|
-
}
|
|
432
|
+
},
|
|
445
433
|
},
|
|
446
|
-
|
|
447
|
-
{
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
434
|
+
]);
|
|
435
|
+
const { startBlock } = await gluegun_1.prompt.ask([
|
|
436
|
+
{
|
|
437
|
+
type: 'input',
|
|
438
|
+
name: 'startBlock',
|
|
439
|
+
message: 'Start Block',
|
|
440
|
+
initial: initStartBlock || '0',
|
|
441
|
+
skip: () => initFromExample !== undefined,
|
|
442
|
+
validate: value => parseInt(value) >= 0,
|
|
443
|
+
result(value) {
|
|
444
|
+
if (initStartBlock)
|
|
445
|
+
return initStartBlock;
|
|
446
|
+
return value;
|
|
447
|
+
},
|
|
457
448
|
},
|
|
458
|
-
|
|
459
|
-
{
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
contractName = value;
|
|
468
|
-
return value;
|
|
449
|
+
]);
|
|
450
|
+
const { contractName } = await gluegun_1.prompt.ask([
|
|
451
|
+
{
|
|
452
|
+
type: 'input',
|
|
453
|
+
name: 'contractName',
|
|
454
|
+
message: 'Contract Name',
|
|
455
|
+
initial: initContractName || 'Contract',
|
|
456
|
+
skip: () => initFromExample !== undefined || !protocolInstance.hasContract(),
|
|
457
|
+
validate: value => value && value.length > 0,
|
|
469
458
|
},
|
|
470
|
-
|
|
471
|
-
{
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
indexEvents = value;
|
|
479
|
-
return value;
|
|
459
|
+
]);
|
|
460
|
+
const { indexEvents } = await gluegun_1.prompt.ask([
|
|
461
|
+
{
|
|
462
|
+
type: 'confirm',
|
|
463
|
+
name: 'indexEvents',
|
|
464
|
+
message: 'Index contract events as entities',
|
|
465
|
+
initial: true,
|
|
466
|
+
skip: () => !!initIndexEvents,
|
|
480
467
|
},
|
|
481
|
-
|
|
482
|
-
];
|
|
483
|
-
try {
|
|
484
|
-
const answers = await gluegun_1.prompt.ask(questions);
|
|
468
|
+
]);
|
|
485
469
|
return {
|
|
486
|
-
...answers,
|
|
487
470
|
abi: abiFromEtherscan || abiFromFile,
|
|
488
471
|
protocolInstance,
|
|
472
|
+
subgraphName,
|
|
473
|
+
directory,
|
|
474
|
+
studio: product === 'subgraph-studio',
|
|
475
|
+
startBlock,
|
|
476
|
+
fromExample: !!initFromExample,
|
|
477
|
+
product,
|
|
478
|
+
network,
|
|
479
|
+
contractName,
|
|
480
|
+
contract,
|
|
481
|
+
indexEvents,
|
|
489
482
|
};
|
|
490
483
|
}
|
|
491
484
|
catch (e) {
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.49.0-alpha-
|
|
3
|
+
"version": "0.49.0-alpha-20230504000723-2c6e265",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"license": "(Apache-2.0 OR MIT)",
|
|
6
6
|
"engines": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dockerode": "2.5.8",
|
|
32
32
|
"fs-extra": "9.1.0",
|
|
33
33
|
"glob": "9.3.5",
|
|
34
|
-
"gluegun": "
|
|
34
|
+
"gluegun": "5.1.2",
|
|
35
35
|
"graphql": "15.5.0",
|
|
36
36
|
"immutable": "4.2.1",
|
|
37
37
|
"ipfs-http-client": "55.0.0",
|