Skip to content

Commit 87e74ce

Browse files
authored
feat: allow publishing new version for subgraphs on network (#1690)
* feat: allow publishing new version * handle opening on txn in correct txn explorer * handle publishing new subgraph version * prettier * remove gql env * commit * lint * new line * allow passing network * handle network * fix
1 parent fb69b33 commit 87e74ce

File tree

11 files changed

+819
-55
lines changed

11 files changed

+819
-55
lines changed

.changeset/nice-ants-flow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphprotocol/graph-cli': minor
3+
'website': minor
4+
---
5+
6+
allow publishing new subgraph version

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ packages/cli/tests/cli/validation
77
packages/cli/tests/cli/add
88
pnpm-lock.yaml
99
cf-pages/**
10+
website/src/graphql-env.d.ts

packages/cli/src/commands/publish.ts

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import chalk from 'chalk';
22
import { print } from 'gluegun';
33
import open from 'open';
44
import { Args, Command, Flags, ux } from '@oclif/core';
5+
// eslint-disable-next-line no-restricted-imports
6+
import { URL, URLSearchParams } from '@whatwg-node/fetch';
57
import { createCompiler } from '../command-helpers/compiler';
68
import * as DataSourcesExtractor from '../command-helpers/data-sources';
79
import { DEFAULT_IPFS_URL } from '../command-helpers/ipfs';
@@ -20,6 +22,17 @@ export default class PublishCommand extends Command {
2022
help: Flags.help({
2123
char: 'h',
2224
}),
25+
'subgraph-id': Flags.string({
26+
summary: 'Subgraph ID to publish to.',
27+
required: false,
28+
}),
29+
'protocol-network': Flags.string({
30+
summary: 'The network to use for the subgraph deployment.',
31+
options: ['arbitrum-one', 'arbitrum-sepolia'],
32+
default: 'arbitrum-one',
33+
required: false,
34+
dependsOn: ['subgraph-id'],
35+
}),
2336
ipfs: Flags.string({
2437
summary: 'Upload build results to an IPFS node.',
2538
char: 'i',
@@ -39,7 +52,17 @@ export default class PublishCommand extends Command {
3952
/**
4053
* Prompt the user to open up the browser to continue publishing the subgraph
4154
*/
42-
async publishWithBrowser({ ipfsHash, webapp }: { ipfsHash: string; webapp: string }) {
55+
async publishWithBrowser({
56+
ipfsHash,
57+
webapp,
58+
subgraphId,
59+
protocolNetwork,
60+
}: {
61+
ipfsHash: string;
62+
webapp: string;
63+
subgraphId: string | undefined;
64+
protocolNetwork: string | undefined;
65+
}) {
4366
const answer = await ux.prompt(
4467
`Press ${chalk.green(
4568
'y',
@@ -52,23 +75,42 @@ export default class PublishCommand extends Command {
5275
this.exit(0);
5376
}
5477

55-
const URL = `${webapp}?id=${ipfsHash}`;
78+
const url = new URL(webapp);
79+
80+
const searchParams = new URLSearchParams(url.search);
81+
searchParams.set('id', ipfsHash);
82+
if (subgraphId) {
83+
searchParams.set('subgraphId', subgraphId);
84+
}
85+
if (protocolNetwork) {
86+
searchParams.set('network', protocolNetwork);
87+
}
88+
89+
url.search = searchParams.toString();
90+
91+
const openUrl = url.toString();
5692

5793
print.success(
58-
`Finalize the publish of the subgraph from the Graph CLI publish page. Opening up the browser to continue publishing at ${URL}`,
94+
`Finalize the publish of the subgraph from the Graph CLI publish page. Opening up the browser to continue publishing at ${openUrl}`,
5995
);
60-
await open(URL);
96+
await open(openUrl);
6197
return;
6298
}
6399

64100
async run() {
65101
const {
66102
args: { 'subgraph-manifest': manifest },
67-
flags: { 'ipfs-hash': ipfsHash, 'webapp-url': webUiUrl, ipfs },
103+
flags: {
104+
'ipfs-hash': ipfsHash,
105+
'webapp-url': webUiUrl,
106+
ipfs,
107+
'subgraph-id': subgraphId,
108+
'protocol-network': protocolNetwork,
109+
},
68110
} = await this.parse(PublishCommand);
69111

70112
if (ipfsHash) {
71-
await this.publishWithBrowser({ ipfsHash, webapp: webUiUrl });
113+
await this.publishWithBrowser({ ipfsHash, webapp: webUiUrl, subgraphId, protocolNetwork });
72114
return;
73115
}
74116

@@ -100,7 +142,12 @@ export default class PublishCommand extends Command {
100142
return;
101143
}
102144

103-
await this.publishWithBrowser({ ipfsHash: result, webapp: webUiUrl });
145+
await this.publishWithBrowser({
146+
ipfsHash: result,
147+
webapp: webUiUrl,
148+
subgraphId,
149+
protocolNetwork,
150+
});
104151
return;
105152
}
106153
}

0 commit comments

Comments
 (0)