9
9
getSubgraphBasename,
10
10
validateSubgraphName,
11
11
} = require ( '../command-helpers/subgraph' )
12
+ const { validateStudioNetwork } = require ( '../command-helpers/studio' )
12
13
const { withSpinner, step } = require ( '../command-helpers/spinner' )
13
14
const { fixParameters } = require ( '../command-helpers/gluegun' )
14
15
const { chooseNodeUrl } = require ( '../command-helpers/node' )
16
+ const { loadManifest } = require ( '../migrations/util/load-manifest' )
15
17
const { abiEvents, generateScaffold, writeScaffold } = require ( '../scaffold' )
16
18
const ABI = require ( '../abi' )
17
19
@@ -381,7 +383,7 @@ module.exports = {
381
383
if ( fromExample && subgraphName && directory ) {
382
384
return await initSubgraphFromExample (
383
385
toolbox ,
384
- { allowSimpleName, directory, subgraphName } ,
386
+ { allowSimpleName, directory, subgraphName, studio , product } ,
385
387
{ commands } ,
386
388
)
387
389
}
@@ -421,7 +423,9 @@ module.exports = {
421
423
network,
422
424
subgraphName,
423
425
contractName,
424
- node
426
+ node,
427
+ studio,
428
+ product,
425
429
} ,
426
430
{ commands } ,
427
431
)
@@ -455,6 +459,8 @@ module.exports = {
455
459
{
456
460
subgraphName : inputs . subgraphName ,
457
461
directory : inputs . directory ,
462
+ studio : inputs . studio ,
463
+ product : inputs . product ,
458
464
} ,
459
465
{ commands } ,
460
466
)
@@ -476,7 +482,9 @@ module.exports = {
476
482
address : inputs . address ,
477
483
indexEvents,
478
484
contractName : inputs . contractName ,
479
- node
485
+ node,
486
+ studio : inputs . studio ,
487
+ product : inputs . product ,
480
488
} ,
481
489
{ commands } ,
482
490
)
@@ -567,7 +575,7 @@ Make sure to visit the documentation on https://thegraph.com/docs/ for further i
567
575
568
576
const initSubgraphFromExample = async (
569
577
toolbox ,
570
- { allowSimpleName, subgraphName, directory } ,
578
+ { allowSimpleName, subgraphName, directory, studio , product } ,
571
579
{ commands } ,
572
580
) => {
573
581
let { filesystem, print, system } = toolbox
@@ -602,6 +610,24 @@ const initSubgraphFromExample = async (
602
610
return
603
611
}
604
612
613
+ try {
614
+ // It doesn't matter if we changed the URL we clone the YAML,
615
+ // we'll check it's network anyway. If it's a studio subgraph we're dealing with.
616
+ let manifestFile = await loadManifest ( path . join ( directory , 'subgraph.yaml' ) )
617
+
618
+ for ( const { network } of manifestFile . dataSources || [ ] ) {
619
+ validateStudioNetwork ( { studio, product, network } )
620
+ }
621
+
622
+ for ( const { network } of manifestFile . templates || [ ] ) {
623
+ validateStudioNetwork ( { studio, product, network } )
624
+ }
625
+ } catch ( e ) {
626
+ print . error ( e . message )
627
+ process . exitCode = 1
628
+ return
629
+ }
630
+
605
631
// Update package.json to match the subgraph name
606
632
let prepared = await withSpinner (
607
633
`Update subgraph name and commands in package.json` ,
@@ -661,7 +687,19 @@ const initSubgraphFromExample = async (
661
687
662
688
const initSubgraphFromContract = async (
663
689
toolbox ,
664
- { allowSimpleName, subgraphName, directory, abi, network, address, indexEvents, contractName, node} ,
690
+ {
691
+ allowSimpleName,
692
+ subgraphName,
693
+ directory,
694
+ abi,
695
+ network,
696
+ address,
697
+ indexEvents,
698
+ contractName,
699
+ node,
700
+ studio,
701
+ product,
702
+ } ,
665
703
{ commands } ,
666
704
) => {
667
705
let { print } = toolbox
@@ -686,6 +724,17 @@ const initSubgraphFromContract = async (
686
724
return
687
725
}
688
726
727
+ // We can validate this before the scaffold because we receive
728
+ // the network from the form or via command line argument.
729
+ // We don't need to read the manifest in this case.
730
+ try {
731
+ validateStudioNetwork ( { studio, product, network } )
732
+ } catch ( e ) {
733
+ print . error ( e . message )
734
+ process . exitCode = 1
735
+ return
736
+ }
737
+
689
738
// Scaffold subgraph from ABI
690
739
let scaffold = await withSpinner (
691
740
`Create subgraph scaffold` ,
0 commit comments