@@ -2,6 +2,8 @@ import chalk from 'chalk';
2
2
import { print } from 'gluegun' ;
3
3
import open from 'open' ;
4
4
import { Args , Command , Flags , ux } from '@oclif/core' ;
5
+ // eslint-disable-next-line no-restricted-imports
6
+ import { URL , URLSearchParams } from '@whatwg-node/fetch' ;
5
7
import { createCompiler } from '../command-helpers/compiler' ;
6
8
import * as DataSourcesExtractor from '../command-helpers/data-sources' ;
7
9
import { DEFAULT_IPFS_URL } from '../command-helpers/ipfs' ;
@@ -20,6 +22,17 @@ export default class PublishCommand extends Command {
20
22
help : Flags . help ( {
21
23
char : 'h' ,
22
24
} ) ,
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
+ } ) ,
23
36
ipfs : Flags . string ( {
24
37
summary : 'Upload build results to an IPFS node.' ,
25
38
char : 'i' ,
@@ -39,7 +52,17 @@ export default class PublishCommand extends Command {
39
52
/**
40
53
* Prompt the user to open up the browser to continue publishing the subgraph
41
54
*/
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
+ } ) {
43
66
const answer = await ux . prompt (
44
67
`Press ${ chalk . green (
45
68
'y' ,
@@ -52,23 +75,42 @@ export default class PublishCommand extends Command {
52
75
this . exit ( 0 ) ;
53
76
}
54
77
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 ( ) ;
56
92
57
93
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 } ` ,
59
95
) ;
60
- await open ( URL ) ;
96
+ await open ( openUrl ) ;
61
97
return ;
62
98
}
63
99
64
100
async run ( ) {
65
101
const {
66
102
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
+ } ,
68
110
} = await this . parse ( PublishCommand ) ;
69
111
70
112
if ( ipfsHash ) {
71
- await this . publishWithBrowser ( { ipfsHash, webapp : webUiUrl } ) ;
113
+ await this . publishWithBrowser ( { ipfsHash, webapp : webUiUrl , subgraphId , protocolNetwork } ) ;
72
114
return ;
73
115
}
74
116
@@ -100,7 +142,12 @@ export default class PublishCommand extends Command {
100
142
return ;
101
143
}
102
144
103
- await this . publishWithBrowser ( { ipfsHash : result , webapp : webUiUrl } ) ;
145
+ await this . publishWithBrowser ( {
146
+ ipfsHash : result ,
147
+ webapp : webUiUrl ,
148
+ subgraphId,
149
+ protocolNetwork,
150
+ } ) ;
104
151
return ;
105
152
}
106
153
}
0 commit comments