name: golang description: GraphStructManager Go 1.25 + Gremlin guidelines
Overview
You are maintaining GraphStructManager, a type-safe, chainable Gremlin query builder for Go. Prioritize correctness, predictable API behavior, and clear mapping between Go structs and Gremlin traversals.
Inspiration
- The API is inspired by GORM, but adapted for graph databases and Gremlin traversals rather than SQL.
Repository Context
- Go version: 1.25 (module
github.com/jbrusegaard/graph-struct-manager) - Gremlin: Apache TinkerPop
gremlin-gov3.7.4 - Core packages:
gremlin/driver,gsmtypes,comparator,log - Public surface: generic query builder (
Query[T gsmtypes.VertexType]) and helper APIs
Graph Model Conventions
- Vertex structs must embed
gsmtypes.Vertexanonymously;Create/Updatevalidate this. - Edge structs (when used) embed
gsmtypes.Edgeand implementgsmtypes.EdgeType. - Use
gremlin:"field_name"tags for properties;gremlin:"field_name,omitempty"skips zero values and nil pointers during create/update. - Use
gremlinSubTraversal:"alias"for subtraversal projections; the alias must matchAddSubTraversalusage. - Use
gremlinEdge:"edge_label[,out|in|both]"for related-vertex fields loaded viaPreload(goFieldName); nested paths use dots (Preload("Topics.Posts")). These fields are never persisted as properties. - Label resolution:
Label() stringwins; empty label defaults to snake_case struct name.
Query Builder Design
- Keep methods chainable and consistent with existing behavior (mutate query, return
*Query[T]). - Use
comparatorconstants for predicates; map them to GremlinP/TextPconsistently. - Preserve debug string building and
GSM_DEBUGbehavior when adding query steps. Rangeis ignored whenOffsetis set; maintain this behavior and warnings.Take()returns the first result;ID()performs fast ID lookup usingHasLabel.
Struct Mapping and Tags
structToMapdrives create/update; it ignoresgremlinSubTraversaltags.UnloadGremlinResultIntoStructmaps Gremlin results to tagged fields, including anonymous embedded structs and subtraversal aliases.- When changing mapping rules, update tests under
gremlin/driver/*_test.go.
Logging and Diagnostics
- Logging uses
log.InitializeLogger()andGSM_LOG_LEVEL. - Query debugging uses
GSM_DEBUG=trueto emit generated traversal strings.
Error Handling
- Return explicit errors; wrap with context (
fmt.Errorf("context: %w", err)). - Avoid panics and hidden behavior changes; align error messages with existing usage.
Testing and Docs
- Prefer table-driven tests and cover exported behavior.
- If you change public API or query semantics, update
README.mdexamples to match.