Resolve a graph reference to an actual graph instance This function properly handles session-based graph resolution per ISO GQL standard. When graph_expr is CurrentGraph, it will use the session's current graph if available.
(
&self,
graph_expr: Option<&GraphExpression>,
session: Option<&Arc<std::sync::RwLock<crate::session::models::UserSession>>>,
)
| 467 | /// This function properly handles session-based graph resolution per ISO GQL standard. |
| 468 | /// When graph_expr is CurrentGraph, it will use the session's current graph if available. |
| 469 | fn resolve_graph_reference( |
| 470 | &self, |
| 471 | graph_expr: Option<&GraphExpression>, |
| 472 | session: Option<&Arc<std::sync::RwLock<crate::session::models::UserSession>>>, |
| 473 | ) -> Result<Arc<GraphCache>, ExecutionError> { |
| 474 | match graph_expr { |
| 475 | Some(GraphExpression::Reference(catalog_path)) => { |
| 476 | // Explicit graph reference - resolve directly |
| 477 | let graph_name = catalog_path.to_string(); |
| 478 | |
| 479 | match self.lazy_load_graph(&graph_name)? { |
| 480 | Some(graph) => { |
| 481 | log::debug!("Resolved graph reference to existing graph: {}", graph_name); |
| 482 | Ok(Arc::new(graph)) |
| 483 | } |
| 484 | None => { |
| 485 | log::debug!("Graph '{}' not found, creating empty graph", graph_name); |
| 486 | // Create empty graph for new graphs created via CREATE GRAPH |
| 487 | let empty_graph = GraphCache::new(); |
| 488 | if let Err(e) = self.storage.save_graph(&graph_name, empty_graph.clone()) { |
| 489 | log::warn!("Failed to add empty graph '{}': {}", graph_name, e); |
| 490 | } |
| 491 | Ok(Arc::new(empty_graph)) |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | Some(GraphExpression::CurrentGraph) => { |
| 496 | // CurrentGraph marker - resolve from session per ISO GQL standard |
| 497 | if let Some(session_lock) = session { |
| 498 | if let Ok(session_guard) = session_lock.read() { |
| 499 | if let Some(current_graph_path) = &session_guard.current_graph { |
| 500 | match self.storage.get_graph(current_graph_path)? { |
| 501 | Some(graph) => { |
| 502 | log::debug!( |
| 503 | "Resolved CurrentGraph from session: {}", |
| 504 | current_graph_path |
| 505 | ); |
| 506 | return Ok(Arc::new(graph)); |
| 507 | } |
| 508 | None => { |
| 509 | return Err(ExecutionError::RuntimeError(format!( |
| 510 | "Session graph '{}' not found", |
| 511 | current_graph_path |
| 512 | ))); |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | // No session or no current graph set |
| 519 | Err(ExecutionError::RuntimeError( |
| 520 | "CurrentGraph reference requires session with SET GRAPH. Use SESSION SET GRAPH <path> first.".to_string() |
| 521 | )) |
| 522 | } |
| 523 | Some(GraphExpression::Union { |
| 524 | left, |
| 525 | right, |
| 526 | all: _, |
no test coverage detected