@@ -204,6 +204,61 @@ async fn spawn_block_ingestor(
204
204
graph:: spawn_blocking ( job_runner. start ( ) ) ;
205
205
}
206
206
207
+ fn deploy_subgraph_from_flag (
208
+ subgraph : String ,
209
+ opt : & Opt ,
210
+ subgraph_registrar : Arc < impl SubgraphRegistrar > ,
211
+ node_id : NodeId ,
212
+ ) {
213
+ let ( name, hash) = if subgraph. contains ( ':' ) {
214
+ let mut split = subgraph. split ( ':' ) ;
215
+ ( split. next ( ) . unwrap ( ) , split. next ( ) . unwrap ( ) . to_owned ( ) )
216
+ } else {
217
+ ( "cli" , subgraph)
218
+ } ;
219
+
220
+ let name = SubgraphName :: new ( name)
221
+ . expect ( "Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'" ) ;
222
+ let subgraph_id = DeploymentHash :: new ( hash) . expect ( "Subgraph hash must be a valid IPFS hash" ) ;
223
+ let debug_fork = opt
224
+ . debug_fork
225
+ . clone ( )
226
+ . map ( DeploymentHash :: new)
227
+ . map ( |h| h. expect ( "Debug fork hash must be a valid IPFS hash" ) ) ;
228
+ let start_block = opt
229
+ . start_block
230
+ . clone ( )
231
+ . map ( |block| {
232
+ let mut split = block. split ( ':' ) ;
233
+ (
234
+ // BlockHash
235
+ split. next ( ) . unwrap ( ) . to_owned ( ) ,
236
+ // BlockNumber
237
+ split. next ( ) . unwrap ( ) . parse :: < i64 > ( ) . unwrap ( ) ,
238
+ )
239
+ } )
240
+ . map ( |( hash, number) | BlockPtr :: try_from ( ( hash. as_str ( ) , number) ) )
241
+ . map ( Result :: unwrap) ;
242
+
243
+ graph:: spawn (
244
+ async move {
245
+ subgraph_registrar. create_subgraph ( name. clone ( ) ) . await ?;
246
+ subgraph_registrar
247
+ . create_subgraph_version (
248
+ name,
249
+ subgraph_id,
250
+ node_id,
251
+ debug_fork,
252
+ start_block,
253
+ None ,
254
+ None ,
255
+ )
256
+ . await
257
+ }
258
+ . map_err ( |e| panic ! ( "Failed to deploy subgraph from `--subgraph` flag: {}" , e) ) ,
259
+ ) ;
260
+ }
261
+
207
262
pub async fn run ( opt : Opt , env_vars : Arc < EnvVars > ) {
208
263
env_logger:: init ( ) ;
209
264
// Set up logger
@@ -308,7 +363,7 @@ pub async fn run(opt: Opt, env_vars: Arc<EnvVars>) {
308
363
309
364
// TODO: make option loadable from configuration TOML and environment:
310
365
let expensive_queries =
311
- read_expensive_queries ( & logger, opt. expensive_queries_filename ) . unwrap ( ) ;
366
+ read_expensive_queries ( & logger, opt. expensive_queries_filename . clone ( ) ) . unwrap ( ) ;
312
367
313
368
let ( primary_pool, subscription_manager, chain_head_update_listener, network_store) =
314
369
setup_store (
@@ -446,52 +501,7 @@ pub async fn run(opt: Opt, env_vars: Arc<EnvVars>) {
446
501
447
502
// Add the CLI subgraph with a REST request to the admin server.
448
503
if let Some ( subgraph) = subgraph {
449
- let ( name, hash) = if subgraph. contains ( ':' ) {
450
- let mut split = subgraph. split ( ':' ) ;
451
- ( split. next ( ) . unwrap ( ) , split. next ( ) . unwrap ( ) . to_owned ( ) )
452
- } else {
453
- ( "cli" , subgraph)
454
- } ;
455
-
456
- let name = SubgraphName :: new ( name)
457
- . expect ( "Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'" ) ;
458
- let subgraph_id =
459
- DeploymentHash :: new ( hash) . expect ( "Subgraph hash must be a valid IPFS hash" ) ;
460
- let debug_fork = opt
461
- . debug_fork
462
- . map ( DeploymentHash :: new)
463
- . map ( |h| h. expect ( "Debug fork hash must be a valid IPFS hash" ) ) ;
464
- let start_block = opt
465
- . start_block
466
- . map ( |block| {
467
- let mut split = block. split ( ':' ) ;
468
- (
469
- // BlockHash
470
- split. next ( ) . unwrap ( ) . to_owned ( ) ,
471
- // BlockNumber
472
- split. next ( ) . unwrap ( ) . parse :: < i64 > ( ) . unwrap ( ) ,
473
- )
474
- } )
475
- . map ( |( hash, number) | BlockPtr :: try_from ( ( hash. as_str ( ) , number) ) )
476
- . map ( Result :: unwrap) ;
477
-
478
- graph:: spawn (
479
- async move {
480
- subgraph_registrar. create_subgraph ( name. clone ( ) ) . await ?;
481
- subgraph_registrar
482
- . create_subgraph_version (
483
- name,
484
- subgraph_id,
485
- node_id,
486
- debug_fork,
487
- start_block,
488
- None ,
489
- None ,
490
- )
491
- . await
492
- }
493
- . map_err ( |e| panic ! ( "Failed to deploy subgraph from `--subgraph` flag: {}" , e) ) ,
494
- ) ;
504
+ deploy_subgraph_from_flag ( subgraph, & opt, subgraph_registrar. clone ( ) , node_id) ;
495
505
}
496
506
497
507
// Serve GraphQL queries over HTTP
0 commit comments