How to use gremlin - 10 common examples

To help you get started, we’ve selected a few gremlin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-samples / amazon-neptune-samples / gremlin / visjs-neptune / indexLambda.js View on Github external
body: JSON.stringify(nodes)
        };
        console.log("Initialize call response: " + JSON.stringify(data));
        callback(null, response);
        context.done();
        dc.close(); // look at this carefully!!!
    }).
        catch(error => {
            console.log('ERROR', error);
        dc.close();
    });
    }


    if (event.pathParameters.proxy.match(/search/ig)) {
        g.V().has('name', gremlin.process.P.between(event.queryStringParameters.username, event.queryStringParameters.touser)).limit(20).valueMap(true).toList().then(
            data => {
            console.log(JSON.stringify(data));
            var response = {
            statusCode: 200,
            headers: headers,
            body: JSON.stringify(data)
        };
        console.log("Search call response: " + JSON.stringify(data));
        callback(null, response);
        context.done();
        dc.close(); // look at this carefully!!!
    }).
        catch(error => {
            console.log('ERROR', error);
        dc.close();
    });
github aws-samples / amazon-neptune-samples / gremlin / visjs-neptune / indexLambda.js View on Github external
exports.handler = function(event, context, callback) {

    var DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
    var Graph = gremlin.structure.Graph;
    //Use wss:// for secure connections. See https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-ssl.html 
    dc = new DriverRemoteConnection('wss://'+process.env.NEPTUNE_CLUSTER_ENDPOINT+':'+process.env.NEPTUNE_PORT+'/gremlin');
    var graph = new Graph();
    var g = graph.traversal().withRemote(dc);

    const headers = {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'OPTIONS, POST, GET',
        'Access-Control-Max-Age': 2592000, // 30 days
        /** add other headers as per requirement */
        'Access-Control-Allow-Headers' : '*',
        "Content-Type": "application/json"
    };

    console.log("Path Parameters => "+ event.pathParameters);
github Azure-Samples / azure-cosmos-db-graph-npm-bom-sample / webapp / dao / cosmosdb_dao.js View on Github external
this.cosmos_gremlin_uri    = process.env.AZURE_COSMOSDB_GRAPHDB_URI;    // https://cjoakimcosmosdbgremlin.documents.azure.com:443/
        this.cosmos_gremlin_wssuri = 'wss://' + this.cosmos_gremlin_acct + '.gremlin.cosmosdb.azure.com:443/gremlin';
        this.graph_coll_link       = '/dbs/' + this.cosmos_gremlin_db + '/colls/' + this.cosmos_gremlin_graph;

        console.log('cosmos_gremlin_acct:   ' + this.cosmos_gremlin_acct);
        console.log('cosmos_gremlin_db:     ' + this.cosmos_gremlin_db);
        console.log('cosmos_gremlin_graph:  ' + this.cosmos_gremlin_graph);
        console.log('cosmos_gremlin_views:  ' + this.cosmos_gremlin_views);
        console.log('cosmos_gremlin_wssuri: ' + this.cosmos_gremlin_wssuri);
        console.log('graph_coll_link:       ' + this.graph_coll_link); 

        // Gremlin client
        var guri  = this.cosmos_gremlin_wssuri;
        var gkey  = this.cosmos_gremlin_key
        var glink = this.graph_coll_link;
        var authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(glink, gkey);
        this.gremlin_client = new gremlin.driver.Client(
            guri, 
            { 
                authenticator,
                traversalsource : "g",
                rejectUnauthorized : true,
                mimeType : "application/vnd.gremlin-v2.0+json"
            }
        );

        // SQL client
        var suri = this.cosmos_gremlin_uri; 
        var skey = this.cosmos_gremlin_key;
        this.sql_client = new CosmosClient({ endpoint: suri, auth: { masterKey: skey } });
    }
github Azure-Samples / azure-cosmos-db-graph-npm-bom-sample / webapp / dao / cosmosdb_dao.js View on Github external
this.cosmos_gremlin_wssuri = 'wss://' + this.cosmos_gremlin_acct + '.gremlin.cosmosdb.azure.com:443/gremlin';
        this.graph_coll_link       = '/dbs/' + this.cosmos_gremlin_db + '/colls/' + this.cosmos_gremlin_graph;

        console.log('cosmos_gremlin_acct:   ' + this.cosmos_gremlin_acct);
        console.log('cosmos_gremlin_db:     ' + this.cosmos_gremlin_db);
        console.log('cosmos_gremlin_graph:  ' + this.cosmos_gremlin_graph);
        console.log('cosmos_gremlin_views:  ' + this.cosmos_gremlin_views);
        console.log('cosmos_gremlin_wssuri: ' + this.cosmos_gremlin_wssuri);
        console.log('graph_coll_link:       ' + this.graph_coll_link); 

        // Gremlin client
        var guri  = this.cosmos_gremlin_wssuri;
        var gkey  = this.cosmos_gremlin_key
        var glink = this.graph_coll_link;
        var authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(glink, gkey);
        this.gremlin_client = new gremlin.driver.Client(
            guri, 
            { 
                authenticator,
                traversalsource : "g",
                rejectUnauthorized : true,
                mimeType : "application/vnd.gremlin-v2.0+json"
            }
        );

        // SQL client
        var suri = this.cosmos_gremlin_uri; 
        var skey = this.cosmos_gremlin_key;
        this.sql_client = new CosmosClient({ endpoint: suri, auth: { masterKey: skey } });
    }
github inolen / gremlin-node / examples / titanExample.js View on Github external
var TitanFactory = g.java.import('com.thinkaurelius.titan.core.TitanFactory');
var gt = TitanFactory.openSync(conf);
g.SetGraph(gt);

gt.makeTypeSync().nameSync("foo").dataTypeSync(Type.String.class).indexedSync(Type.Vertex.class)
 	.uniqueSync(Direction.BOTH, UniqCon.NO_LOCK).makePropertyKeySync();

// var vertex = gt.addVertexSync(null);
// vertex.setPropertySync('name', 'Frank');
// gt.commitSync();

//g.v(8, 12).consoleOut();
// g.E().has('weight', T.gt, g.Float(0.2)).property('weight').consoleOut();
// g.V('name','Frank').consoleOut();
g.V().consoleOut();
console.log("All good!");
github inolen / gremlin-node / examples / titanExample.js View on Github external
/*Titan specific Enums <<<<<*/
//console.log(TTC.LABEL.toString());
//console.log(TTC.KEY.toString());
//console.log(UniqCon.LOCK.toString());
//console.log(UniqCon.NO_LOCK.toString());

var BaseConfiguration = g.java.import('org.apache.commons.configuration.BaseConfiguration');

conf = new BaseConfiguration();
conf.setPropertySync("storage.backend","cassandra");
conf.setPropertySync("storage.hostname","127.0.0.1");
conf.setPropertySync("storage.keyspace","titan");

var TitanFactory = g.java.import('com.thinkaurelius.titan.core.TitanFactory');
var gt = TitanFactory.openSync(conf);
g.SetGraph(gt);

gt.makeTypeSync().nameSync("foo").dataTypeSync(Type.String.class).indexedSync(Type.Vertex.class)
 	.uniqueSync(Direction.BOTH, UniqCon.NO_LOCK).makePropertyKeySync();

// var vertex = gt.addVertexSync(null);
// vertex.setPropertySync('name', 'Frank');
// gt.commitSync();

//g.v(8, 12).consoleOut();
// g.E().has('weight', T.gt, g.Float(0.2)).property('weight').consoleOut();
// g.V('name','Frank').consoleOut();
g.V().consoleOut();
console.log("All good!");
github aws-samples / amazon-neptune-samples / gremlin / visjs-neptune / indexLambda.js View on Github external
exports.handler = function(event, context, callback) {

    var DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
    var Graph = gremlin.structure.Graph;
    //Use wss:// for secure connections. See https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-ssl.html 
    dc = new DriverRemoteConnection('wss://'+process.env.NEPTUNE_CLUSTER_ENDPOINT+':'+process.env.NEPTUNE_PORT+'/gremlin');
    var graph = new Graph();
    var g = graph.traversal().withRemote(dc);

    const headers = {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'OPTIONS, POST, GET',
        'Access-Control-Max-Age': 2592000, // 30 days
        /** add other headers as per requirement */
        'Access-Control-Allow-Headers' : '*',
        "Content-Type": "application/json"
    };

    console.log("Path Parameters => "+ event.pathParameters);
    console.log("event.pathParameters.proxy => "+ event.pathParameters.proxy);
github microsoft / vscode-cosmosdb / src / graph / GraphViewServer.ts View on Github external
private async executeQuery(queryId: number, gremlinQuery: string): Promise {
    this.log(`Executing query #${queryId}: ${gremlinQuery}`);

    const client = gremlin.createClient(
      this._configuration.endpointPort,
      this._configuration.endpoint,
      {
        "session": false,
        "ssl": this._configuration.endpointPort === 443 || this._configuration.endpointPort === 8080,
        "user": `/dbs/${this._configuration.databaseName}/colls/${this._configuration.graphName}`,
        "password": this._configuration.key
      });

    // Patch up handleProtocolMessage as a temporary work-around for https://github.com/jbmusso/gremlin-javascript/issues/93
    var originalHandleProtocolMessage = client.handleProtocolMessage;
    client.handleProtocolMessage = function handleProtocolMessage(message) {
      if (!message.binary) {
        // originalHandleProtocolMessage isn't handling non-binary messages, so convert this one back to binary
        message.data = new Buffer(message.data);
        message.binary = true;
github gremlin-orm / gremlin-orm / src / gremlin-orm.js View on Github external
constructor(dialect, port, url, options) {
    // Constants
    this.DIALECTS = {AZURE: 'azure'};
    this.STRING = 'string';
    this.NUMBER = 'number';
    this.BOOLEAN = 'boolean';
    this.DATE = 'date';

    const argLength = arguments.length;
    if (argLength === 0) {
      this.client = null;
    } else if (argLength === 1) {
      this.client = Gremlin.createClient();
    } else if (argLength === 3) {
      this.client = Gremlin.createClient(port, url);
    } else {
      this.client = Gremlin.createClient(port, url, options);
    }
    if (Array.isArray(dialect)) {
      this.dialect = dialect[0];
      this.partition = dialect[1];
    }
    else {
      this.dialect = dialect;
    }
    this.definedVertices = {};
    this.definedEdges = {};
    this.vertexModel = VertexModel;
    this.edgeModel = EdgeModel;
github gremlin-orm / gremlin-orm / src / gremlin-orm.js View on Github external
constructor(dialect, port, url, options) {
    // Constants
    this.DIALECTS = {AZURE: 'azure'};
    this.STRING = 'string';
    this.NUMBER = 'number';
    this.BOOLEAN = 'boolean';
    this.DATE = 'date';

    const argLength = arguments.length;
    if (argLength === 0) {
      this.client = null;
    } else if (argLength === 1) {
      this.client = Gremlin.createClient();
    } else if (argLength === 3) {
      this.client = Gremlin.createClient(port, url);
    } else {
      this.client = Gremlin.createClient(port, url, options);
    }
    if (Array.isArray(dialect)) {
      this.dialect = dialect[0];
      this.partition = dialect[1];
    }
    else {
      this.dialect = dialect;
    }
    this.definedVertices = {};
    this.definedEdges = {};
    this.vertexModel = VertexModel;
    this.edgeModel = EdgeModel;
  }