@@ -77,10 +77,11 @@ const processInitForm = async (
77
77
allowSimpleName,
78
78
directory,
79
79
contract,
80
+ indexEvents,
80
81
fromExample,
81
82
network,
82
83
subgraphName,
83
- contractName
84
+ contractName,
84
85
} ,
85
86
) => {
86
87
let abiFromEtherscan = undefined
@@ -108,10 +109,13 @@ const processInitForm = async (
108
109
message : 'Product for which to initialize' ,
109
110
choices : [ 'subgraph-studio' , 'hosted-service' ] ,
110
111
skip : ( ) =>
111
- protocol === 'arweave' || protocol === 'cosmos' || protocol === 'near' ||
112
+ protocol === 'arweave' ||
113
+ protocol === 'cosmos' ||
114
+ protocol === 'near' ||
112
115
product === 'subgraph-studio' ||
113
116
product === 'hosted-service' ||
114
- studio !== undefined || node !== undefined ,
117
+ studio !== undefined ||
118
+ node !== undefined ,
115
119
result : value => {
116
120
// For now we only support NEAR subgraphs in the Hosted Service
117
121
if ( protocol === 'near' ) {
@@ -131,7 +135,8 @@ const processInitForm = async (
131
135
{
132
136
type : 'input' ,
133
137
name : 'subgraphName' ,
134
- message : ( ) => product == 'subgraph-studio' || studio ? 'Subgraph slug' : 'Subgraph name' ,
138
+ message : ( ) =>
139
+ product == 'subgraph-studio' || studio ? 'Subgraph slug' : 'Subgraph name' ,
135
140
initial : subgraphName ,
136
141
validate : name => {
137
142
try {
@@ -198,9 +203,7 @@ const processInitForm = async (
198
203
// Validate whether the contract is valid
199
204
const { valid, error } = validateContract ( value , ProtocolContract )
200
205
201
- return valid
202
- ? true
203
- : error
206
+ return valid ? true : error
204
207
} ,
205
208
result : async value => {
206
209
if ( fromExample !== undefined ) {
@@ -254,7 +257,18 @@ const processInitForm = async (
254
257
result : value => {
255
258
contractName = value
256
259
return value
257
- }
260
+ } ,
261
+ } ,
262
+ {
263
+ type : 'confirm' ,
264
+ name : 'indexEvents' ,
265
+ message : 'Index contract events as entities' ,
266
+ initial : true ,
267
+ skip : ( ) => ! ! indexEvents ,
268
+ result : value => {
269
+ indexEvents = value
270
+ return value
271
+ } ,
258
272
} ,
259
273
]
260
274
@@ -305,7 +319,12 @@ module.exports = {
305
319
} = toolbox . parameters . options
306
320
307
321
node = node || g
308
- ; ( { node, allowSimpleName } = chooseNodeUrl ( { product, studio, node, allowSimpleName } ) )
322
+ ; ( { node, allowSimpleName } = chooseNodeUrl ( {
323
+ product,
324
+ studio,
325
+ node,
326
+ allowSimpleName,
327
+ } ) )
309
328
310
329
if ( fromContract && fromExample ) {
311
330
print . error ( `Only one of --from-example and --from-contract can be used at a time.` )
@@ -320,7 +339,7 @@ module.exports = {
320
339
help,
321
340
h,
322
341
indexEvents,
323
- studio
342
+ studio,
324
343
} )
325
344
} catch ( e ) {
326
345
print . error ( e . message )
@@ -375,7 +394,11 @@ module.exports = {
375
394
// go straight to creating the subgraph from an existing contract
376
395
if ( fromContract && protocol && subgraphName && directory && network && node ) {
377
396
if ( ! protocolChoices . includes ( protocol ) ) {
378
- print . error ( `Protocol '${ protocol } ' is not supported, choose from these options: ${ protocolChoices . join ( ', ' ) } ` )
397
+ print . error (
398
+ `Protocol '${ protocol } ' is not supported, choose from these options: ${ protocolChoices . join (
399
+ ', ' ,
400
+ ) } `,
401
+ )
379
402
process . exitCode = 1
380
403
return
381
404
}
@@ -420,7 +443,7 @@ module.exports = {
420
443
contractName,
421
444
node,
422
445
studio,
423
- product
446
+ product,
424
447
} ,
425
448
{ commands, addContract : false } ,
426
449
)
@@ -436,10 +459,11 @@ module.exports = {
436
459
allowSimpleName,
437
460
directory,
438
461
contract : fromContract ,
462
+ indexEvents,
439
463
fromExample,
440
464
network,
441
465
subgraphName,
442
- contractName
466
+ contractName,
443
467
} )
444
468
445
469
// Exit immediately when the form is cancelled
@@ -466,7 +490,7 @@ module.exports = {
466
490
product : inputs . product ,
467
491
studio,
468
492
node,
469
- allowSimpleName
493
+ allowSimpleName,
470
494
} ) )
471
495
await initSubgraphFromContract (
472
496
toolbox ,
@@ -478,11 +502,11 @@ module.exports = {
478
502
abi : inputs . abi ,
479
503
network : inputs . network ,
480
504
contract : inputs . contract ,
481
- indexEvents,
505
+ indexEvents : inputs . indexEvents ,
482
506
contractName : inputs . contractName ,
483
507
node,
484
508
studio : inputs . studio ,
485
- product : inputs . product
509
+ product : inputs . product ,
486
510
} ,
487
511
{ commands, addContract : true } ,
488
512
)
@@ -617,24 +641,23 @@ const initSubgraphFromExample = async (
617
641
618
642
try {
619
643
await system . run (
620
- `git clone http://github.com/graphprotocol/example-subgraphs ${ tmpDir } `
644
+ `git clone http://github.com/graphprotocol/example-subgraphs ${ tmpDir } ` ,
621
645
)
622
646
623
647
// If an example is not specified, use the default one
624
648
if ( fromExample === undefined || fromExample === true ) {
625
649
fromExample = DEFAULT_EXAMPLE_SUBGRAPH
626
650
}
627
651
628
- const exampleSubgraphPath = path . join ( tmpDir , fromExample ) ;
652
+ const exampleSubgraphPath = path . join ( tmpDir , fromExample )
629
653
630
654
if ( ! filesystem . exists ( exampleSubgraphPath ) ) {
631
655
return { result : false , error : `Example not found: ${ fromExample } ` }
632
656
}
633
657
634
658
filesystem . copy ( exampleSubgraphPath , directory )
635
659
return true
636
- }
637
- finally {
660
+ } finally {
638
661
filesystem . remove ( tmpDir )
639
662
}
640
663
} ,
@@ -647,7 +670,9 @@ const initSubgraphFromExample = async (
647
670
try {
648
671
// It doesn't matter if we changed the URL we clone the YAML,
649
672
// we'll check it's network anyway. If it's a studio subgraph we're dealing with.
650
- const dataSourcesAndTemplates = await DataSourcesExtractor . fromFilePath ( path . join ( directory , 'subgraph.yaml' ) )
673
+ const dataSourcesAndTemplates = await DataSourcesExtractor . fromFilePath (
674
+ path . join ( directory , 'subgraph.yaml' ) ,
675
+ )
651
676
652
677
for ( const { network } of dataSourcesAndTemplates ) {
653
678
validateStudioNetwork ( { studio, product, network } )
@@ -658,7 +683,7 @@ const initSubgraphFromExample = async (
658
683
return
659
684
}
660
685
661
- let networkConf = await initNetworksConfig ( toolbox , directory , " address" )
686
+ let networkConf = await initNetworksConfig ( toolbox , directory , ' address' )
662
687
if ( networkConf !== true ) {
663
688
process . exitCode = 1
664
689
return
@@ -740,7 +765,7 @@ const initSubgraphFromContract = async (
740
765
contractName,
741
766
node,
742
767
studio,
743
- product
768
+ product,
744
769
} ,
745
770
{ commands, addContract } ,
746
771
) => {
@@ -854,7 +879,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
854
879
type : 'input' ,
855
880
name : 'contract' ,
856
881
message : ( ) => `Contract ${ ProtocolContract . identifierName ( ) } ` ,
857
- validate : async ( value ) => {
882
+ validate : async value => {
858
883
// Validate whether the contract is valid
859
884
const { valid, error } = validateContract ( value , ProtocolContract )
860
885
return valid ? true : error
@@ -865,7 +890,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
865
890
name : 'localAbi' ,
866
891
message : 'Provide local ABI path?' ,
867
892
choices : [ 'yes' , 'no' ] ,
868
- result : ( value ) => {
893
+ result : value => {
869
894
abiFromFile = value === 'yes' ? true : false
870
895
return abiFromFile
871
896
} ,
@@ -874,19 +899,19 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
874
899
type : 'input' ,
875
900
name : 'abi' ,
876
901
message : 'ABI file (path)' ,
877
- skip : ( ) => abiFromFile === false
902
+ skip : ( ) => abiFromFile === false ,
878
903
} ,
879
904
{
880
905
type : 'input' ,
881
906
name : 'contractName' ,
882
907
message : 'Contract Name' ,
883
908
initial : 'Contract' ,
884
- validate : ( value ) => value && value . length > 0 ,
909
+ validate : value => value && value . length > 0 ,
885
910
} ,
886
911
]
887
912
888
913
// Get the cwd before process.chdir in order to switch back in the end of command execution
889
- const cwd = process . cwd ( ) ;
914
+ const cwd = process . cwd ( )
890
915
891
916
try {
892
917
let { abi, contract, contractName } = await toolbox . prompt . ask ( questions )
@@ -909,8 +934,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
909
934
} catch ( e ) {
910
935
toolbox . print . error ( e )
911
936
process . exit ( 1 )
912
- }
913
- finally {
937
+ } finally {
914
938
process . chdir ( cwd )
915
939
}
916
940
}
0 commit comments