Skip to content

Commit f5ffcf1

Browse files
authored
fix: respect --protocol and --network for graph init (#1508)
1 parent 4b92a5e commit f5ffcf1

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

.changeset/lucky-crabs-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': patch
3+
---
4+
5+
respect `--protocol` and `--network` provided from flags of `graph init`

packages/cli/src/commands/init.ts

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { generateScaffold, writeScaffold } from '../command-helpers/scaffold';
1515
import { withSpinner } from '../command-helpers/spinner';
1616
import { validateStudioNetwork } from '../command-helpers/studio';
1717
import { getSubgraphBasename, validateSubgraphName } from '../command-helpers/subgraph';
18+
import debugFactory from '../debug';
1819
import Protocol, { ProtocolName } from '../protocols';
1920
import EthereumABI from '../protocols/ethereum/abi';
2021
import { abiEvents } from '../scaffold/schema';
@@ -26,6 +27,8 @@ const availableNetworks = Protocol.availableNetworks();
2627

2728
const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar';
2829

30+
const initDebugger = debugFactory('graph-cli:commands:init');
31+
2932
export default class InitCommand extends Command {
3033
static description = 'Creates a new subgraph with basic scaffolding.';
3134

@@ -115,24 +118,27 @@ export default class InitCommand extends Command {
115118
async run() {
116119
const {
117120
args: { subgraphName, directory },
118-
flags: {
119-
protocol,
120-
product,
121-
studio,
122-
node: nodeFlag,
123-
'allow-simple-name': allowSimpleNameFlag,
124-
'from-contract': fromContract,
125-
'contract-name': contractName,
126-
'from-example': fromExample,
127-
'index-events': indexEvents,
128-
'skip-install': skipInstall,
129-
network,
130-
abi: abiPath,
131-
'start-block': startBlock,
132-
spkg: spkgPath,
133-
},
121+
flags,
134122
} = await this.parse(InitCommand);
135123

124+
const {
125+
protocol,
126+
product,
127+
studio,
128+
node: nodeFlag,
129+
'allow-simple-name': allowSimpleNameFlag,
130+
'from-contract': fromContract,
131+
'contract-name': contractName,
132+
'from-example': fromExample,
133+
'index-events': indexEvents,
134+
'skip-install': skipInstall,
135+
network,
136+
abi: abiPath,
137+
'start-block': startBlock,
138+
spkg: spkgPath,
139+
} = flags;
140+
141+
initDebugger('Flags: %O', flags);
136142
let { node, allowSimpleName } = chooseNodeUrl({
137143
product,
138144
// if we are loading example, we want to ensure we are using studio
@@ -480,10 +486,19 @@ async function processInitForm(
480486
message: 'Protocol',
481487
choices: protocolChoices,
482488
skip: protocolChoices.includes(String(initProtocol) as ProtocolName),
489+
result: value => {
490+
if (initProtocol) {
491+
initDebugger.extend('processInitForm')('initProtocol: %O', initProtocol);
492+
return initProtocol;
493+
}
494+
initDebugger.extend('processInitForm')('protocol: %O', value);
495+
return value;
496+
},
483497
});
484498

485499
const protocolInstance = new Protocol(protocol);
486500
const isSubstreams = protocol === 'substreams';
501+
initDebugger.extend('processInitForm')('isSubstreams: %O', isSubstreams);
487502

488503
const { product } = await prompt.ask<{
489504
product: 'subgraph-studio' | 'hosted-service';
@@ -563,9 +578,13 @@ async function processInitForm(
563578
choices: availableNetworks
564579
.get(protocol as ProtocolName) // Get networks related to the chosen protocol.
565580
?.toArray() || ['mainnet'],
566-
skip: initFromExample !== undefined,
581+
skip: initNetwork !== undefined,
567582
result: value => {
568-
if (initNetwork) return initNetwork;
583+
if (initNetwork) {
584+
initDebugger.extend('processInitForm')('initNetwork: %O', initNetwork);
585+
return initNetwork;
586+
}
587+
initDebugger.extend('processInitForm')('network: %O', value);
569588
return value;
570589
},
571590
},

0 commit comments

Comments
 (0)