콘텐츠로 이동
Graph 문서0.5

핵심 모델

최신 안정판 Graph 0.5.1 릴리스 기준

핵심 추상화 지도

GraphElementId는 비어 있지 않은 문자열을 감싼 값 클래스다. Long이나 드라이버 ID를 공통 형태로 바꾸지만, 애플리케이션은 그 값을 해석하지 말고 불투명한 식별자로 다뤄야 한다. 구현과 검증: GraphElementId.kt, GraphElementIdTest.kt.

GraphVertex(id, label, properties)GraphEdge(id, label, startId, endId, properties)는 불변 스냅샷이다. 속성 값은 null일 수 있지만 실제로 저장할 수 있는 형식은 백엔드와 파일 형식에 따라 달라진다. 소스: GraphVertex.kt, GraphEdge.kt.

GraphPathPathStep.VertexStepPathStep.EdgeStep을 담는다. vertices, edges, length, totalWeight는 여기서 계산한다. 정점만 넘겨 만든 경로에는 간선이 저절로 생기지 않는다. GraphPath.ktGraphPathTest.kt를 함께 보자.

val id = GraphElementId.of("person:42")
val person = GraphVertex(id, "Person", mapOf("name" to "Ada"))

반환 객체를 살아 있는 엔티티처럼 수정하지 않는다. 변경은 repository 메서드로 기록하고, 가져오기 파일의 외부 ID와 백엔드 ID를 분리한다.

TinkerGraphOperations().use { ops ->
val a: GraphVertex = ops.createVertex("Person", mapOf("name" to "Alice"))
val b: GraphVertex = ops.createVertex("Person", mapOf("name" to "Bob"))
val e: GraphEdge = ops.createEdge(a.id, b.id, "KNOWS", mapOf("since" to 2024))
val p: GraphPath? = ops.shortestPath(a.id, b.id, PathOptions(edgeLabel = "KNOWS", maxDepth = 1))
check(e.startId == a.id && e.endId == b.id)
check(p?.length == 1 && p.vertices.map { it.id } == listOf(a.id, b.id))
}

백엔드가 만든 ID는 비어 있지 않아야 하고, 간선 방향은 Alice에서 Bob으로 유지돼야 한다. 경로에는 정점 둘과 간선 하나가 나온다. GraphSuspendOperations에서도 같은 의미를 확인하되 Flow 반환은 소유한 코루틴 범위 안에서 소비한다.

GraphElementId.of("")는 백엔드 질의 전에 실패해야 한다. import 간선의 끝점을 못 찾았다고 ID 문자열을 해석하지 말고 외부-ID map을 확인한다.

Terminal window
./gradlew :bluetape4k-graph-core:test --tests '*GraphElementIdTest' --tests '*GraphPathTest'