@graphprotocol/graph-cli 0.64.1 → 0.65.0-alpha-20240111170628-733b724

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,5 +1,13 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
+ ## 0.65.0-alpha-20240111170628-733b724
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1557](https://github.com/graphprotocol/graph-tooling/pull/1557)
8
+ [`d9ce44f`](https://github.com/graphprotocol/graph-tooling/commit/d9ce44f2730b56097f6accbbc4f1090327e54d89)
9
+ Thanks [@saihaj](https://github.com/saihaj)! - fetch supported networks from API
10
+
3
11
  ## 0.64.1
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -37,14 +37,26 @@ or a local directory for debugging, and deploys the subgraph to a
37
37
 
38
38
  ## Installation
39
39
 
40
- The Graph CLI can be installed with `npm` or `yarn`:
40
+ We recommend install the CLI using package manager `npm` or `yarn` or `pnpm` when developing
41
+ subgraphs locally:
41
42
 
42
43
  ```sh
43
44
  # NPM
44
- npm install -g @graphprotocol/graph-cli
45
+ npm install @graphprotocol/graph-cli
45
46
 
46
47
  # Yarn
47
- yarn global add @graphprotocol/graph-cli
48
+ yarn add @graphprotocol/graph-cli
49
+
50
+ # pnpm
51
+ pnpm install @graphprotocol/graph-cli
52
+ ```
53
+
54
+ You can install the CLI globally using a binary. Eventually this will become the default mechanism
55
+ for installing the CLI and building subgraphs because users do not need to install `Node.js` or any
56
+ other external dependencies.
57
+
58
+ ```sh
59
+ curl -LS https://cli.thegraph.com/install.sh | sudo sh
48
60
  ```
49
61
 
50
62
  ### On Linux
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { URL } from 'url';
3
+ export declare const SUBGRAPH_STUDIO_URL = "https://api.studio.thegraph.com/deploy/";
3
4
  export declare const validateNodeUrl: (node: string) => URL;
4
5
  export declare const normalizeNodeUrl: (node: string) => string;
5
6
  export declare function chooseNodeUrl({ product, studio, node, allowSimpleName, }: {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHostedServiceSubgraphId = exports.chooseNodeUrl = exports.normalizeNodeUrl = exports.validateNodeUrl = void 0;
3
+ exports.getHostedServiceSubgraphId = exports.chooseNodeUrl = exports.normalizeNodeUrl = exports.validateNodeUrl = exports.SUBGRAPH_STUDIO_URL = void 0;
4
4
  const url_1 = require("url");
5
5
  const gluegun_1 = require("gluegun");
6
6
  const constants_1 = require("../constants");
7
- const SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/';
7
+ exports.SUBGRAPH_STUDIO_URL = 'https://api.studio.thegraph.com/deploy/';
8
8
  const HOSTED_SERVICE_URL = 'https://api.thegraph.com/deploy/';
9
9
  const HOSTED_SERVICE_INDEX_NODE_URL = 'https://api.thegraph.com/index-node/graphql';
10
10
  const validateNodeUrl = (node) => new url_1.URL(node);
@@ -27,7 +27,7 @@ function chooseNodeUrl({ product, studio, node, allowSimpleName, }) {
27
27
  }
28
28
  switch (product) {
29
29
  case 'subgraph-studio':
30
- node = SUBGRAPH_STUDIO_URL;
30
+ node = exports.SUBGRAPH_STUDIO_URL;
31
31
  break;
32
32
  case 'hosted-service':
33
33
  node = HOSTED_SERVICE_URL;
@@ -38,15 +38,52 @@ const node_1 = require("../command-helpers/node");
38
38
  const scaffold_1 = require("../command-helpers/scaffold");
39
39
  const spinner_1 = require("../command-helpers/spinner");
40
40
  const subgraph_1 = require("../command-helpers/subgraph");
41
+ const constants_1 = require("../constants");
41
42
  const debug_1 = __importDefault(require("../debug"));
42
43
  const protocols_1 = __importDefault(require("../protocols"));
43
44
  const schema_1 = require("../scaffold/schema");
44
45
  const validation_1 = require("../validation");
45
46
  const add_1 = __importDefault(require("./add"));
46
47
  const protocolChoices = Array.from(protocols_1.default.availableProtocols().keys());
47
- const availableNetworks = protocols_1.default.availableNetworks();
48
- const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar';
49
48
  const initDebugger = (0, debug_1.default)('graph-cli:commands:init');
49
+ /**
50
+ * a dynamic list of available networks supported by the studio
51
+ */
52
+ const AVAILABLE_NETWORKS = async () => {
53
+ const logger = initDebugger.extend('AVAILABLE_NETWORKS');
54
+ try {
55
+ logger('fetching chain_list from studio');
56
+ const res = await fetch(node_1.SUBGRAPH_STUDIO_URL, {
57
+ method: 'POST',
58
+ headers: {
59
+ ...constants_1.GRAPH_CLI_SHARED_HEADERS,
60
+ 'content-type': 'application/json',
61
+ },
62
+ body: JSON.stringify({
63
+ jsonrpc: '2.0',
64
+ id: 1,
65
+ method: 'chain_list',
66
+ params: [],
67
+ }),
68
+ });
69
+ if (!res.ok) {
70
+ logger("Something went wrong while fetching 'chain_list' from studio HTTP code: %o", res.status);
71
+ return null;
72
+ }
73
+ const result = await res.json();
74
+ if (result?.result) {
75
+ logger('chain_list result: %o', result.result);
76
+ return result.result;
77
+ }
78
+ logger("Unable to get result for 'chain_list' from studio: %O", result);
79
+ return null;
80
+ }
81
+ catch (e) {
82
+ logger('error: %O', e);
83
+ return null;
84
+ }
85
+ };
86
+ const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar';
50
87
  class InitCommand extends core_1.Command {
51
88
  async run() {
52
89
  const { args: { subgraphName, directory }, flags, } = await this.parse(InitCommand);
@@ -308,12 +345,8 @@ InitCommand.flags = {
308
345
  }),
309
346
  network: core_1.Flags.string({
310
347
  summary: 'Network the contract is deployed to.',
348
+ description: 'Check https://thegraph.com/docs/en/developing/supported-networks/ for supported networks',
311
349
  dependsOn: ['from-contract'],
312
- options: [
313
- ...availableNetworks.get('ethereum'),
314
- ...availableNetworks.get('near'),
315
- ...availableNetworks.get('cosmos'),
316
- ],
317
350
  }),
318
351
  };
319
352
  exports.default = InitCommand;
@@ -468,14 +501,16 @@ async function processInitForm({ protocol: initProtocol, product: initProduct, s
468
501
  : true,
469
502
  },
470
503
  ]);
504
+ const choices = (await AVAILABLE_NETWORKS())?.[product === 'subgraph-studio' ? 'studio' : 'hostedService'];
505
+ if (!choices) {
506
+ this.error('Unable to fetch available networks from API. Please report this issue. As a workaround you can pass `--network` flag from the available networks: https://thegraph.com/docs/en/developing/supported-networks', { exit: 1 });
507
+ }
471
508
  const { network } = await gluegun_1.prompt.ask([
472
509
  {
473
510
  type: 'select',
474
511
  name: 'network',
475
512
  message: () => `${protocolInstance.displayName()} network`,
476
- choices: availableNetworks
477
- .get(protocol) // Get networks related to the chosen protocol.
478
- ?.toArray() || ['mainnet'],
513
+ choices,
479
514
  skip: initNetwork !== undefined,
480
515
  result: value => {
481
516
  if (initNetwork) {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.64.1",
2
+ "version": "0.65.0-alpha-20240111170628-733b724",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
@@ -632,54 +632,8 @@
632
632
  "name": "network",
633
633
  "type": "option",
634
634
  "summary": "Network the contract is deployed to.",
635
+ "description": "Check https://thegraph.com/docs/en/developing/supported-networks/ for supported networks",
635
636
  "multiple": false,
636
- "options": [
637
- "mainnet",
638
- "rinkeby",
639
- "goerli",
640
- "poa-core",
641
- "poa-sokol",
642
- "gnosis",
643
- "matic",
644
- "mumbai",
645
- "fantom",
646
- "fantom-testnet",
647
- "bsc",
648
- "chapel",
649
- "clover",
650
- "avalanche",
651
- "fuji",
652
- "celo",
653
- "celo-alfajores",
654
- "fuse",
655
- "moonbeam",
656
- "moonriver",
657
- "mbase",
658
- "arbitrum-one",
659
- "arbitrum-goerli",
660
- "arbitrum-sepolia",
661
- "optimism",
662
- "optimism-goerli",
663
- "aurora",
664
- "aurora-testnet",
665
- "base-testnet",
666
- "base",
667
- "zksync-era",
668
- "zksync-era-testnet",
669
- "sepolia",
670
- "polygon-zkevm-testnet",
671
- "polygon-zkevm",
672
- "scroll-sepolia",
673
- "scroll",
674
- "near-mainnet",
675
- "near-testnet",
676
- "cosmoshub-4",
677
- "theta-testnet-001",
678
- "osmosis-1",
679
- "osmo-test-4",
680
- "juno-1",
681
- "uni-3"
682
- ],
683
637
  "dependsOn": [
684
638
  "from-contract"
685
639
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.64.1",
3
+ "version": "0.65.0-alpha-20240111170628-733b724",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {