@@ -47,16 +47,41 @@ impl Subgraph {
4747 Ok ( ( ) )
4848 }
4949
50+ /// Patch source subgraph placeholders in the manifest with their deployment hashes.
51+ /// This must be called after `patch()` since it reads from `subgraph.yaml.patched`.
52+ pub fn patch_sources ( dir : & TestFile , sources : & [ ( String , String ) ] ) -> anyhow:: Result < ( ) > {
53+ if sources. is_empty ( ) {
54+ return Ok ( ( ) ) ;
55+ }
56+
57+ let patched_path = dir. path . join ( "subgraph.yaml.patched" ) ;
58+ let mut content = fs:: read_to_string ( & patched_path) ?;
59+
60+ for ( placeholder, deployment_hash) in sources {
61+ let repl = format ! ( "@{}@" , placeholder) ;
62+ content = content. replace ( & repl, deployment_hash) ;
63+ }
64+
65+ fs:: write ( & patched_path, content) ?;
66+ Ok ( ( ) )
67+ }
68+
5069 /// Prepare the subgraph for deployment by patching contracts and checking for subgraph datasources
5170 pub async fn prepare (
5271 name : & str ,
5372 contracts : & [ Contract ] ,
73+ sources : Option < & [ ( String , String ) ] > ,
5474 ) -> anyhow:: Result < ( TestFile , String , bool ) > {
5575 let dir = Self :: dir ( name) ;
5676 let name = format ! ( "test/{name}" ) ;
5777
5878 Self :: patch ( & dir, contracts) . await ?;
5979
80+ // Patch source subgraph placeholders if provided
81+ if let Some ( sources) = sources {
82+ Self :: patch_sources ( & dir, sources) ?;
83+ }
84+
6085 // Check if subgraph has subgraph datasources
6186 let yaml_content = fs:: read_to_string ( dir. path . join ( "subgraph.yaml.patched" ) ) ?;
6287 let yaml: serde_yaml:: Value = serde_yaml:: from_str ( & yaml_content) ?;
@@ -68,9 +93,15 @@ impl Subgraph {
6893 Ok ( ( dir, name, has_subgraph_datasource) )
6994 }
7095
71- /// Deploy the subgraph by running the required `graph` commands
72- pub async fn deploy ( name : & str , contracts : & [ Contract ] ) -> anyhow:: Result < String > {
73- let ( dir, name, has_subgraph_datasource) = Self :: prepare ( name, contracts) . await ?;
96+ /// Deploy the subgraph by running the required `graph` commands.
97+ /// If `sources` is provided, the deployment hashes will be used to patch
98+ /// source subgraph placeholders (e.g., `@source-subgraph@`) in the manifest.
99+ pub async fn deploy (
100+ name : & str ,
101+ contracts : & [ Contract ] ,
102+ sources : Option < & [ ( String , String ) ] > ,
103+ ) -> anyhow:: Result < String > {
104+ let ( dir, name, has_subgraph_datasource) = Self :: prepare ( name, contracts, sources) . await ?;
74105
75106 // graph codegen subgraph.yaml
76107 let mut prog = Command :: new ( & CONFIG . graph_cli ) ;
0 commit comments