@@ -437,10 +437,24 @@ async fn generate_subgraph_source_types(
437437
438438 let ipfs_client = IpfsClient :: new ( ipfs_url) ?;
439439
440+ // Validate that all subgraph data source names are unique
441+ let mut seen_names = std:: collections:: HashSet :: new ( ) ;
442+ for source in subgraph_sources {
443+ if !seen_names. insert ( & source. name ) {
444+ return Err ( anyhow ! (
445+ "Duplicate subgraph data source name '{}'. Each subgraph data source must have a unique name." ,
446+ source. name
447+ ) ) ;
448+ }
449+ }
450+
440451 for source in subgraph_sources {
441452 step (
442453 Step :: Load ,
443- & format ! ( "Fetch schema for subgraph {}" , source. address) ,
454+ & format ! (
455+ "Fetch schema for subgraph {} ({})" ,
456+ source. name, source. address
457+ ) ,
444458 ) ;
445459
446460 // Fetch schema from IPFS using block_in_place to allow blocking in async context
@@ -452,16 +466,19 @@ async fn generate_subgraph_source_types(
452466
453467 step (
454468 Step :: Generate ,
455- & format ! ( "Generate types for subgraph {}" , source. address) ,
469+ & format ! (
470+ "Generate types for subgraph {} ({})" ,
471+ source. name, source. address
472+ ) ,
456473 ) ;
457474
458475 // Generate entity types WITHOUT store methods (false = no store methods)
459476 let generator = match SchemaCodeGenerator :: new ( & ast) {
460477 Ok ( gen) => gen,
461478 Err ( e) => {
462479 eprintln ! (
463- "Warning: Failed to create schema generator for subgraph {}: {}" ,
464- source. address, e
480+ "Warning: Failed to create schema generator for subgraph {} ({}) : {}" ,
481+ source. name , source . address, e
465482 ) ;
466483 continue ;
467484 }
@@ -474,8 +491,9 @@ async fn generate_subgraph_source_types(
474491 let code = generate_file ( & imports, & entity_classes) ;
475492 let formatted = try_format_typescript ( & code) ;
476493
477- // Output to: <output_dir>/subgraph-<IPFS_HASH>.ts
478- let output_file = output_dir. join ( format ! ( "subgraph-{}.ts" , source. address) ) ;
494+ // Output to: <output_dir>/subgraph-<NAME>.ts
495+ // Using name instead of IPFS hash for stable file names
496+ let output_file = output_dir. join ( format ! ( "subgraph-{}.ts" , source. name) ) ;
479497 step (
480498 Step :: Write ,
481499 & format ! ( "Write types to {}" , output_file. display( ) ) ,
@@ -542,6 +560,8 @@ struct DataSource {
542560/// These reference another subgraph by its IPFS deployment ID.
543561#[ derive( Debug ) ]
544562struct SubgraphSource {
563+ /// The data source name from the manifest
564+ name : String ,
545565 /// The IPFS hash (deployment ID) of the referenced subgraph
546566 address : String ,
547567}
@@ -596,13 +616,20 @@ fn load_manifest(path: &Path) -> Result<Manifest> {
596616 let kind = ds. get ( "kind" ) . and_then ( |k| k. as_str ( ) ) . unwrap_or ( "" ) ;
597617
598618 if kind == "subgraph" {
599- // Subgraph data source - extract the IPFS address
619+ // Subgraph data source - extract the name and IPFS address
620+ let name = ds
621+ . get ( "name" )
622+ . and_then ( |n| n. as_str ( ) )
623+ . unwrap_or ( "unnamed" )
624+ . to_string ( ) ;
625+
600626 if let Some ( address) = ds
601627 . get ( "source" )
602628 . and_then ( |s| s. get ( "address" ) )
603629 . and_then ( |a| a. as_str ( ) )
604630 {
605631 subgraph_sources. push ( SubgraphSource {
632+ name,
606633 address : address. to_string ( ) ,
607634 } ) ;
608635 }
0 commit comments