@@ -153,7 +153,7 @@ pub struct MutationRoot;
153153
154154#[ Object ]
155155impl MutationRoot {
156- /// Create a new triple
156+ /// Create a new triple (routed through the same path as REST for DAG/Raft consistency)
157157 async fn create_triple ( & self , ctx : & Context < ' _ > , input : TripleInput ) -> Result < Triple > {
158158 let state = ctx. data :: < AppState > ( ) ?;
159159
@@ -165,9 +165,45 @@ impl MutationRoot {
165165 object,
166166 ) ;
167167
168+ // Insert triple + record DAG action (same path as REST API)
168169 {
169170 let graph = state. graph . read ( ) . await ;
170171 graph. insert ( triple. clone ( ) ) ?;
172+
173+ #[ cfg( feature = "dag" ) ]
174+ if let Some ( dag_store) = graph. dag_store ( ) {
175+ let dag_author = state
176+ . dag_author
177+ . clone ( )
178+ . unwrap_or_else ( || aingle_graph:: NodeId :: named ( "node:local" ) ) ;
179+ let dag_seq = state
180+ . dag_seq_counter
181+ . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: SeqCst ) ;
182+ let parents = dag_store. tips ( ) . unwrap_or_default ( ) ;
183+
184+ let mut action = aingle_graph:: dag:: DagAction {
185+ parents,
186+ author : dag_author,
187+ seq : dag_seq,
188+ timestamp : chrono:: Utc :: now ( ) ,
189+ payload : aingle_graph:: dag:: DagPayload :: TripleInsert {
190+ triples : vec ! [ aingle_graph:: dag:: TripleInsertPayload {
191+ subject: input. subject. clone( ) ,
192+ predicate: input. predicate. clone( ) ,
193+ object: serde_json:: json!( { } ) ,
194+ } ] ,
195+ } ,
196+ signature : None ,
197+ } ;
198+
199+ if let Some ( ref key) = state. dag_signing_key {
200+ key. sign ( & mut action) ;
201+ }
202+
203+ dag_store. put ( & action) . map_err ( |e| {
204+ Error :: new ( format ! ( "DAG action failed: {e}" ) )
205+ } ) ?;
206+ }
171207 }
172208
173209 // Broadcast event
@@ -183,7 +219,7 @@ impl MutationRoot {
183219 Ok ( triple. into ( ) )
184220 }
185221
186- /// Delete a triple by ID
222+ /// Delete a triple by ID (routed through the same path as REST for DAG/Raft consistency)
187223 async fn delete_triple ( & self , ctx : & Context < ' _ > , id : ID ) -> Result < bool > {
188224 let state = ctx. data :: < AppState > ( ) ?;
189225
@@ -192,7 +228,43 @@ impl MutationRoot {
192228
193229 let deleted = {
194230 let graph = state. graph . read ( ) . await ;
195- graph. delete ( & triple_id) ?
231+ let result = graph. delete ( & triple_id) ?;
232+
233+ #[ cfg( feature = "dag" ) ]
234+ if result {
235+ if let Some ( dag_store) = graph. dag_store ( ) {
236+ let dag_author = state
237+ . dag_author
238+ . clone ( )
239+ . unwrap_or_else ( || aingle_graph:: NodeId :: named ( "node:local" ) ) ;
240+ let dag_seq = state
241+ . dag_seq_counter
242+ . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: SeqCst ) ;
243+ let parents = dag_store. tips ( ) . unwrap_or_default ( ) ;
244+
245+ let mut action = aingle_graph:: dag:: DagAction {
246+ parents,
247+ author : dag_author,
248+ seq : dag_seq,
249+ timestamp : chrono:: Utc :: now ( ) ,
250+ payload : aingle_graph:: dag:: DagPayload :: TripleDelete {
251+ triple_ids : vec ! [ * triple_id. as_bytes( ) ] ,
252+ subjects : vec ! [ ] ,
253+ } ,
254+ signature : None ,
255+ } ;
256+
257+ if let Some ( ref key) = state. dag_signing_key {
258+ key. sign ( & mut action) ;
259+ }
260+
261+ dag_store. put ( & action) . map_err ( |e| {
262+ Error :: new ( format ! ( "DAG action failed: {e}" ) )
263+ } ) ?;
264+ }
265+ }
266+
267+ result
196268 } ;
197269
198270 if deleted {
0 commit comments