wolf4ood/gremlin-rs

Question: using custom ids

Opened this issue · 4 comments

Hi, is there a way to set our own Id property for vertices and edges when creating them ?

I need the same feature. Tryied passing ~id property and upsert with coalesce (could not implement because I can't underst how to use coalesce), but look like it is not possible to use a custom id.

I do not believe TinkerPop3 has this ability out of the box. You can reference each Step here.

I did find that JanusGraph has the ability to store custom vertex IDs, here's the relevant documentation.

I've had success doing it to JanusGraph via an anonymous traversal like inside a coalesce

g.V("custom_vertex_id").fold().coalesce::<Vertex, _>([__.unfold(),
__.add_v("some_label_here")
.property(gremlin_client::structure::T::Id, custom_vertex_id)])

But it doesn't seem like you can do on a traversal directly. If you try to do something like:
graph.get_traversal().add_v("some_label_here").property(gremlin_client::structure::T::Id, custom_vertex_id) you fight the type system.

@wolf4ood The property() method there has a hard type requirement that key be &str, whereas the property() for an anonymous traversal (__ returns a TraversalBuilder) takes a key of type Into<GValue>. Not sure if that's intentional?

I took a stab at adding custom id support in my fork's branch. They're featured in this PR if anyone wants to try the branch until it gets merged & release.