@graphprotocol/graph-cli 0.51.2-alpha-20230620194216-37a1e4d → 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 CHANGED
@@ -1,13 +1,12 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.51.2-alpha-20230620194216-37a1e4d
3
+ ## 0.51.2-alpha-20230621173826-ff8058f
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - [#1382](https://github.com/graphprotocol/graph-tooling/pull/1382)
8
- [`37a1e4d`](https://github.com/graphprotocol/graph-tooling/commit/37a1e4d1beaed7f069d617194f24e5449aa74ded)
9
- Thanks [@saihaj](https://github.com/saihaj)! - Only ask directory and subgraph name when using
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
 
@@ -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");
@@ -59,12 +83,15 @@ class InitCommand extends core_1.Command {
59
83
  };
60
84
  // If all parameters are provided from the command-line,
61
85
  // go straight to creating the subgraph from the example
62
- if (fromExample && subgraphName && directory) {
86
+ if (fromExample && subgraphName && directory && protocol) {
63
87
  await initSubgraphFromExample.bind(this)({
64
88
  fromExample,
65
89
  allowSimpleName,
66
90
  directory,
67
91
  subgraphName,
92
+ studio,
93
+ product,
94
+ protocolInstance: new protocols_1.default(protocol),
68
95
  }, { commands });
69
96
  // Exit with success
70
97
  return this.exit(0);
@@ -122,46 +149,40 @@ class InitCommand extends core_1.Command {
122
149
  // Exit with success
123
150
  return this.exit(0);
124
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
+ }
125
175
  if (fromExample) {
126
- const answers = await processFromExampleInitForm.bind(this)({
127
- allowSimpleName,
128
- subgraphName,
129
- directory,
130
- });
131
- if (!answers) {
132
- this.exit(1);
133
- return;
134
- }
135
176
  await initSubgraphFromExample.bind(this)({
136
177
  fromExample,
137
178
  subgraphName: answers.subgraphName,
138
179
  directory: answers.directory,
180
+ studio: answers.studio,
181
+ product: answers.product,
182
+ protocolInstance: answers.protocolInstance,
139
183
  }, { commands });
140
184
  }
141
185
  else {
142
- // Otherwise, take the user through the interactive form
143
- const answers = await processInitForm.bind(this)({
144
- protocol: protocol,
145
- product,
146
- studio,
147
- node,
148
- abi,
149
- abiPath,
150
- allowSimpleName,
151
- directory,
152
- contract: fromContract,
153
- indexEvents,
154
- fromExample,
155
- network,
156
- subgraphName,
157
- contractName,
158
- startBlock,
159
- spkgPath,
160
- });
161
- if (!answers) {
162
- this.exit(1);
163
- return;
164
- }
165
186
  ({ node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
166
187
  product: answers.product,
167
188
  studio: answers.studio,
@@ -264,51 +285,6 @@ InitCommand.flags = {
264
285
  }),
265
286
  };
266
287
  exports.default = InitCommand;
267
- async function processFromExampleInitForm({ directory: initDirectory, subgraphName: initSubgraphName, allowSimpleName: initAllowSimpleName, }) {
268
- try {
269
- const { subgraphName } = await gluegun_1.prompt.ask([
270
- {
271
- type: 'input',
272
- name: 'subgraphName',
273
- // TODO: is defaulting to studio ok?
274
- message: () => 'Subgraph slug',
275
- initial: initSubgraphName,
276
- validate: name => {
277
- try {
278
- (0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
279
- return true;
280
- }
281
- catch (e) {
282
- return `${e.message}
283
-
284
- Examples:
285
-
286
- $ graph init ${os_1.default.userInfo().username}/${name}
287
- $ graph init ${name} --allow-simple-name`;
288
- }
289
- },
290
- },
291
- ]);
292
- const { directory } = await gluegun_1.prompt.ask([
293
- {
294
- type: 'input',
295
- name: 'directory',
296
- message: 'Directory to create the subgraph in',
297
- initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
298
- validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
299
- ? 'Directory already exists'
300
- : true,
301
- },
302
- ]);
303
- return {
304
- subgraphName,
305
- directory,
306
- };
307
- }
308
- catch (e) {
309
- this.error(e, { exit: 1 });
310
- }
311
- }
312
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, }) {
313
289
  let abiFromEtherscan = undefined;
314
290
  try {
@@ -646,9 +622,8 @@ Subgraph ${subgraphName} created in ${relativeDir}
646
622
 
647
623
  Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
648
624
  }
649
- async function initSubgraphFromExample({
650
- // protocolInstance,
651
- fromExample, allowSimpleName, subgraphName, directory, }, { commands, }) {
625
+ async function initSubgraphFromExample({ protocolInstance, fromExample, allowSimpleName, subgraphName, directory, studio, product, }, { commands, }) {
626
+ const isSubstreams = protocolInstance.name === 'substreams';
652
627
  // Fail if the subgraph name is invalid
653
628
  if (!revalidateSubgraphName.bind(this)(subgraphName, { allowSimpleName })) {
654
629
  process.exitCode = 1;
@@ -688,6 +663,17 @@ fromExample, allowSimpleName, subgraphName, directory, }, { commands, }) {
688
663
  this.exit(1);
689
664
  return;
690
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
+ }
691
677
  const networkConf = await (0, network_1.initNetworksConfig)(directory, 'address');
692
678
  if (networkConf !== true) {
693
679
  this.exit(1);
@@ -734,14 +720,14 @@ fromExample, allowSimpleName, subgraphName, directory, }, { commands, }) {
734
720
  this.exit(1);
735
721
  return;
736
722
  }
737
- // if (!isSubstreams) {
738
- // // Run code-generation
739
- // const codegen = await runCodegen(directory, commands.codegen);
740
- // if (codegen !== true) {
741
- // this.exit(1);
742
- // return;
743
- // }
744
- // }
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
+ }
730
+ }
745
731
  printNextSteps.bind(this)({ subgraphName, directory }, { commands });
746
732
  }
747
733
  async function initSubgraphFromContract({ protocolInstance, allowSimpleName, subgraphName, directory, abi, network, contract, indexEvents, contractName, node, studio, product, startBlock, spkgPath, }, { commands, addContract, }) {
@@ -60,6 +60,7 @@ class TypeGenerator {
60
60
  async generateTypes() {
61
61
  if (this.protocol.name === 'substreams') {
62
62
  toolbox.print.success('Subgraph uses a substream datasource. Codegeneration is not required.');
63
+ process.exit(0);
63
64
  return;
64
65
  }
65
66
  try {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.51.2-alpha-20230620194216-37a1e4d",
2
+ "version": "0.51.2-alpha-20230621173826-ff8058f",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.51.2-alpha-20230620194216-37a1e4d",
3
+ "version": "0.51.2-alpha-20230621173826-ff8058f",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {