jbmusso / gremlin-javascript

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

addE() syntax #65

Closed batwicket closed 7 years ago

batwicket commented 7 years ago

hi..

I'm trying to add an edge to the graph, but the proper/best addE() usage is eluding me. Probably simple. I'm currently using: g.V(${fromVertexId}).addE(${edgelbl}).to(${toVertexId})

gremlin.zip

batwicket commented 7 years ago

The gremlin client sets language to gremlin-groovy, and the titan tutorial says it is using that language:

gremlin> theseus = graph.addVertex('human')
==>v[3328]
gremlin> theseus.property('name', 'theseus')
==>null
gremlin> cerberus = g.V().has('name', 'cerberus').next()
==>v[2816]
gremlin> battle = theseus.addEdge('battled', cerberus, 'time', 22)
==>e[7eo-2kg-iz9-268][3328-battled->2816]

I tried:

`gremlin`g.addV(label, 'god')\ntheseus=g.addV(label, 'human')\ncerberus=g.V().hasLabel('god').next()\ng.V().count()`

but the count was 0. The vertices were not created before the count(). So I tried:

    return this.gremlin`cerberus=g.addV(label, 'god').next()`
        .then(() => {
            return this.gremlin`theseus=g.addV(label, 'human')`
        })
        .then(() => {
            return this.gremlin`g.V().count()`;
        })
        .then(count => {
            console.log('count: ', count);
            return this.gremlin`g.V().hasLabel('human').addE('battled', cerberus, 'time', 22)`;
        })

The count is now ok, but it says 'no such property: cerberus for class: Script62'.

I've probably missed something.. it seems like it should be a common task.

Perhaps your other project, gremlin-script, can generate a valid script?

dragma commented 7 years ago

In you last script (.then(count => {...}) cerebus is nothing. try to add before somthing like cerebus = g.V().hasLabel('god') BTW, I don't think this is an issue for the gremlin-javascript client, you might find more help there : https://groups.google.com/forum/#!forum/gremlin-users Regards, Flo

batwicket commented 7 years ago

thanks Dragma, but i'm not actually assuming that the promise resolutions are carrying state back to the client. I'm assuming a transaction on the server is carrying the variables, which would simplify matters. I did try plugging in g.V().hasLabel('god').. ideally it could be plugged directly into the .addE() expression, but no luck. I think perhaps this interface is designed more for query than mutation because there doesn't appear to be a way to pull, say, cerberus into a JS object then plug it in as a binding to a later expression. I don't really have time to dig into it at this point. Water finds a way...