Working gremlin-javascript example

1,334 vistas
Ir al primer mensaje no leído

jnbank...@gmail.com

no leída,
8 may 2018, 10:53:44 a.m.8/5/18
para Gremlin-users
Hello,

Is there a working javascript example? I started with this following the docs but have run across several errors. Thanks.


const gremlin = require("gremlin");

const graph = new gremlin.structure.Graph();
const g = graph.traversal().withRemote(new gremlin.driver.RemoteConnection('ws://localhost:8182/gremlin'));
g.V().toList().then(function(data) {
console.log(data)
}).catch(function(err) {
console.log(err)
})




Error: submit() was not implemented at RemoteConnection.submit (/Users/julian.bankston/Desktop/repos/service-map/terraform/functions/service_map_add_vertex/node_modules/gremlin/lib/driver/remote-connection.js:39:11) at RemoteStrategy.apply (/Users/julian.bankston/Desktop/repos/service-map/terraform/functions/service_map_add_vertex/node_modules/gremlin/lib/driver/remote-connection.js:66:28) at promise.then (/Users/julian.bankston/Desktop/repos/service-map/terraform/functions/service_map_add_vertex/node_modules/gremlin/lib/process/traversal-strategy.js:55:42) at process._tickCallback (internal/process/next_tick.js:109:7) at Module.runMain (module.js:606:11) at run (bootstrap_node.js:390:7) at startup (bootstrap_node.js:150:9) at bootstrap_node.js:505:3
Se borró el mensaje

Jorge Bay

no leída,
9 may 2018, 10:11:52 a.m.9/5/18
para Gremlin-users
Hi,
You can check the documentation for an example on how to getting started on the JavaScript Gremlin Variant:

In the upcoming versions of the documentation, the example is more clear and complete:

const gremlin = require('gremlin');
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

const graph = new Graph();
const g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));

Note that withRemote() method requires a RemoteConnection implementation, that is DriverRemoteConnection.

With the current version (3.3.2), there are two issues in JavaScript Gremlin that will make getting started a little more difficult. I will detail the issues and the workarounds here, but you should know that version TinkerPop 3.3.3 (available soon!) contains fixes for these issues:

First issue:

The DriverRemoteConnection class is not exported due to a bug in the implementation as detailed in the ticket TINKERPOP-1944, that is going to be fixed in the upcoming version of the GLV. In the meantime, you can import the DriverRemoteConnection class by using:

const DriverRemoteConnection = require('./node_modules/gremlin/lib/driver/driver-remote-connection');

Second issue:

GraphSON3, which is the default serialization format in Gremlin Server 3.3+, is not yet supported in Gremlin-JavaScript. We are planning to support it in the upcoming versions. In the meantime, if you want to use Gremlin-JavaScript against the Gremlin Server 3.3 you must include the GraphSON2 serializer.

In the server yaml configuration file, add the following line under serializers:

  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV2d0] }}

Hope it helps,
Jorge

Jean-Baptiste Musso

no leída,
14 may 2018, 5:11:17 p.m.14/5/18
para gremli...@googlegroups.com
I should add that the code snippet posted by Pavankumar B below is about the old/semi-official version of the JavaScript driver which was published on the v2.x branch on npmjs.org. This library has been superseded by the official JavaScript-GLV (see also: https://github.com/jbmusso/gremlin-javascript/issues/108). Both were/are published under the same name "gremlin" on npmjs.org but with different major versions. Hopefully there'll be less confusion over time.

Jean-Baptiste


On Wed, May 9, 2018 at 1:34 PM Pavankumar B <1pavan...@gmail.com> wrote:
I am putting here what i'm using.

var grem = require('gremlin');
var client = grem.createClient('8182', 'samplehost', { accept: "text/plain" });

var queryGremlin = function(query){
return new Promise((resolve,reject)=>{
client.execute(query,(err,resultSet)=>{
// Close the connection. Call this method only when you are done with the client.
client.closeConnection();
if (err) {
reject(err);
}
else
{
resolve(resultSet);
}
});
});
};

var query = 'g.V().limit(1).valueMap()';
var response = await queryGremlin(query);
console.log(JSON.stringify(response));

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e063dbba-7fd6-4e17-a102-023047feb6f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Mallette

no leída,
14 may 2018, 5:12:49 p.m.14/5/18
para Gremlin-users
We really need a driver that can submit scripts like your old work:


Jean-Baptiste


To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAC3-3jgC3-hcaHh1106%3Df0nyL4wW3ZGhSjBUx%3DJQdki3sk1-ow%40mail.gmail.com.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos