jbmusso / gremlin-javascript

JavaScript tools for graph processing in Node.js and the browser inspired by the Apache TinkerPop API
MIT License
214 stars 63 forks source link

Is direct graph management possible? #106

Closed grreeenn closed 6 years ago

grreeenn commented 6 years ago

Hello,

Thanks a lot for bringing the Gremlin power to JS, incredible work! :) I guess that I have more a question than an issue.

Is it possible to perform management operations on the graph, like adding property fields or indices? I saw that it's possible to make use of conventional Gremlin object names (as g and graph); the conventional name for management object in gremlin console is 'mgmt', but const uuid = await gremlin``mgmt.makePropertyKey('uuid').dataType(UUID.class).cardinality(Cardinality.SINGLE).make()``; returns "No such property: mgmt for class: Script5 (Error 597)".

Do I miss something obvious, or it's just not available at the moment?

(Using JanusGraph 0.2.0-hadoop2 with janusgraph-cassandra-es default config)

Thank you once again :)

jbmusso commented 6 years ago

Hello, thanks for the kind words!

Unless you're using session mode and already instantiated the management instance before, I think you need to instantiate the management instance in the same query. This should help:

const uuid = await gremlin`
  mgmt = graph.openManagement();
  mgmt.makePropertyKey('uuid').dataType(UUID.class).cardinality(Cardinality.SINGLE).make();
`;

Hopefully this helps. Note: I slightly edited your code snippet for formatting reasons.