Giter Site home page Giter Site logo

Comments (16)

jbmusso avatar jbmusso commented on September 17, 2024

Hi Kivo, thanks for showing interested in gRex.

Could you please be more specific about your problem? In particular, which version of gRex are you using? Can you copy/paste a sample of your code so I can help figure out what's wrong?

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

Sure. I can start by saying the tinkerpop graph does not exist. No graph exist actually, and I've been derping around trying to figure out how to create one. The code I have is this:

var Grex = require('grex');

var settings = {
  'database': 'tinkerpop',
  'host': 'localhost',
  'port': 8182
};

Grex.connect(settings, function(err, client) {
  if (err) {
    console.error(err);
  }
  else {
    console.log("Connected to rexster successfully");
  }

  var gremlin = client.gremlin();

  // The following will add 4 vertices and 2 edges in a transaction

  var v1 = gremlin.g.addVertex({ name: 'Foo', age: 20 }, 'v1');
  v1.addProperty('name2', 'testa');
  v1.setProperty('name2', 'updated');

  var v2 = gremlin.g.addVertex({ name:'Bar', age: 30 }, 'v2');
  gremlin.g.addEdge(v1, v2, 'knows', { met: "Somewhere", weight: 1.2 });

  gremlin.exec(function (err, response) {
    console.log(response);
  });
});

It returns the following:

{ message: 'Graph [undefined] could not be found',
  results: [],
  typeMap: {} }

I figured out this means the graph I attemped to connect to doesn't exist. I went to the rexster console and I received the following:

{
version: "2.4.0",
name: "Rexster: A Graph Server",
graphs: [ ],
queryTime: 2.64986,
upTime: "0[d]:08[h]:12[m]:52[s]"
}

This suggest there are no graphs around for me to use. I was wondering how I can create a graph from scratch using rexster, but I had a bad time looking for a good explanation.

Another thing is that I can create a graph in the console, but It wouldn't show up in the REST API.

Also, what's up with having a blank rexster doghouse?

screenshot from 2014-05-26 09 43 27

from grex.

jbmusso avatar jbmusso commented on September 17, 2024

Regarding graph creation, you cannot currently create a graph using gRex. grex.connect() connects you to a previously existing graph on Rexster. Because gRex assumes a graph is already created on Rexster, you will have to manually edit your Rester XML config file and set up a graph there.

The following resource on Rexster wiki should help you configure a graph: https://github.com/tinkerpop/rexster/wiki/Rexster-Configuration

On a side note, and when you're more familiar with Rexster and Graph databases, I suggest you set up Rexster to connect to other graph databases like Titan, OrientDB or Neo4J (to name a few).

As for the blank Rexster doghouse, I supposed this is related to the fact that the graph is missing. I could be wrong, for I never used Doghouse (note that I think it will be dropped in Tinkerpop 3.0).

Let me know if you still have trouble with the set up :). You could also check Tinkerpop's official mailing list there : https://groups.google.com/d/forum/gremlin-users.

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

First I want to thank you for dedicating your time and energy to both a project and a newbie like me. It means a lot while I'm trying to improve. I did change some settings and a couple of graphs were created. The only problem is that I still cant seem to access those graphs from within the node module. In the rexster console I get the following:

rexster[groovy]> rexster.getGraph('NewG')
==>titangraph[cassandra:null]

This explains the graph exist. In my node.js code I do the following:

var Grex = require('grex');


var settings = {
  'database': 'NewG',
  'host': 'localhost',
  'port': 8182
};

Grex.connect(settings, function(err, client) {
  if (err) {
    console.error(err);
  }
  else {
    console.log("Connected to rexster successfully");
  }

  var gremlin = client.gremlin();

  // The following will add 4 vertices and 2 edges in a transaction

  var v1 = gremlin.g.addVertex({ name: 'Foo', age: 20 }, 'v1');
  v1.addProperty('name2', 'testa');
  v1.setProperty('name2', 'updated');

  var v2 = gremlin.g.addVertex({ name:'Bar', age: 30 }, 'v2');
  gremlin.g.addEdge(v1, v2, 'knows', { met: "Somewhere", weight: 1.2 });

  gremlin.exec(function (err, response) {
    console.log("Yay")
    console.log(response);
  });

});

I get the error:

node_modules/grex/src/grex.js:96
      return deferred.reject(e);
                             ^
ReferenceError: e is not defined
    at ClientRequest.<anonymous> (/home/kevin/Programming/Flow/node_modules/grex/src/grex.js:96:30)
    at ClientRequest.EventEmitter.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1547:9)
    at Socket.EventEmitter.emit (events.js:95:17)
    at net.js:440:14
    at process._tickCallback (node.js:419:13)

I have reason to believe that one of my ports are off. But I don't really know if that's completely the case. I was attempting to troubleshoot the problem, but I can't seem to find out which variable the exec method was trying to return.

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

Never mind, I figured out I was using the wrong port. I still have a hang-up on the exec function. On the terminal I get this.

node graph.js
Connected to rexster successfully


The rest remains a blank.

  • Edit *: I checked the rexster-console to see if the information was added, but it wasn't. Thanks for helping me out again.

from grex.

jbmusso avatar jbmusso commented on September 17, 2024

Assuming you're using the latest version of grex on npm, the error you're having is most likely because a variable is missing in a callback declaration there:

https://github.com/gulthor/grex/blob/95b1840c72b8fcd5dba5d5accb2e592e6a22cf74/src/grex.js#L94

(Just to make sure, what version of grex are you using in your package.json?)

This bit of code is responsible for handling any http errors encountered while issueing http requests to Rexster.

This issue was spotted by @celrenheit and I think it was patched on the develop branch and eventually made it to master. But I guess I was wrong! I'll provide a quick fix within a few hours and bump the version on npm.

In the meanwhile, you can manually patch line 94 in /node_modules/grex/src/grex.js and replace it with the following line:

  req.on('error', function(e) {

After this is fixed, or if you don't wish to manually patch /node_modules/grex, issue #29 will help you get a fully working code (indeed, the example code in the README.md is a bit broken and currently misleading). Upcoming v0.6.0 will fix these.

Let me know how it goes.

from grex.

jbmusso avatar jbmusso commented on September 17, 2024

I just published a quick fix on master and published v0.5.7 on npm. Feel free to give it a try and let me know.

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

Hi,

I'm back again. I was finally able to get back to testing the library. It works to an extent. I got an error with the graph I was using. The result was this:

{ success: false,
  api: 
   { description: 'evaluate an ad-hoc Gremlin script for a graph.',
     parameters: 
      { 'rexster.showTypes': 'displays the properties of the elements with their native data type (default is false)',
        load: 'a list of \'stored procedures\' to execute prior to the \'script\' (if \'script\' is not specified then the last script in this argument will return the values',
        language: 'the gremlin language flavor to use (default to groovy)',
        params: 'a map of parameters to bind to the script engine',
        script: 'the Gremlin script to be evaluated',
        'rexster.returnKeys': 'an array of element property keys to return (default is to return all element properties)',
        'rexster.offset.start': 'start index for a paged set of data to be returned',
        'rexster.offset.end': 'end index for a paged set of data to be returned' } },
  message: '',
  error: 'javax.script.ScriptException: java.lang.IllegalArgumentException: Name is reserved: id',
  results: [],
  typeMap: {} }

Any idea what that means?

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

I happened to finally get something working. In my sample code it adds the first vertices, but not the second:

var Grex = require('grex');

var settings = {
  'host': 'localhost',
  'port': 8182,
  'graph': 'graph',
};

// 1. connect() takes two optional parameters: a settings Object and a Node style callback
Grex.connect(settings, function(err, client) {
  if (err) {
    console.error(err);
  }

  // 2. Initialize a Gremlin object to work with
  var gremlin = client.gremlin();

  // Start appending some code
  var v1 = gremlin.g.addVertex({k1:'Hello', 'k2':'v2', k3:'v3', id: 100}, 'vC');
  var v2 = gremlin.g.addVertex({k1:'GoodBoy', 'k2':'Derp', k3:'v3', id: 100}, 'vC');
  // gremlin.g.addEdge(v1, v2, 'pal' , { weight: '0.75f' });

  // 3. Send script for execution, and return a response with the results (if any)
  gremlin.exec(function(err, response) {
    // console.log(response)
  })
});

var v2 fails to be added to the code. And the id is still not set. I think it might have something to do with the Name is reserved: id statement from the response in my previous point.

I would guess that the command craps out because it reaches an error after adding the first vertex.

from grex.

celrenheit avatar celrenheit commented on September 17, 2024

Hello,
I think you are using a reserved name. As said "Name is reserved: id", so you are using the id variable which is reserved.

Can you paste the code you are actually using to get this error ?

from grex.

celrenheit avatar celrenheit commented on September 17, 2024

Your commands craps out in the first .addVertex.
If you change the id variable to _id, you can set a specific id to your vertex.

Also be careful to choose two different id and two different identifier, like so:

  var v1 = gremlin.g.addVertex({k1:'Hello', 'k2':'v2', k3:'v3', _id: 1001}, 'vC');
  var v2 = gremlin.g.addVertex({k1:'GoodBoy', 'k2':'Derp', k3:'v3', _id: 1002}, 'vD');

It will crash in the second .addVertex if you don't change the second id.
If you don't differentiate the identifier 'vC' and 'vD' it will create a relationship to the same vertex (inV: 1002, outV: 1002).

Hope this helps.
Cheers.

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

It looks I can finally close this issue. @gulthor @celrenheit I appreciate both of your help. Thanks a lot.

from grex.

jbmusso avatar jbmusso commented on September 17, 2024

Glad you managed your way out! Please note that gRex api will change a bit
in upcoming v0.6.0, especially when using identifiers in a transaction
context. The documentation will reflect these changes.

On Sunday, June 8, 2014, kivo360 [email protected] wrote:

Closed #30 #30.


Reply to this email directly or view it on GitHub
#30 (comment).

Jean-Baptiste

from grex.

kivo360 avatar kivo360 commented on September 17, 2024

I have one more question. I am attempting to understand the other inner workings of the API. I'm looking to search for a vertex and print the properties. I've typed the following after reading reading some of the documentation:

var Grex = require('grex');

var settings = {
  'host': 'localhost',
  'port': 8182,
  'graph': 'graph',
};

// 1. connect() takes two optional parameters: a settings Object and a Node style callback
Grex.connect(settings, function(err, client) {
  if (err) {
    console.error(err);
  }

  // // 2. Initialize a Gremlin object to work with
  var gremlin = client.gremlin();

  // // Start appending some code
  // var v1 = gremlin.g.addVertex({fname:'Karen', lname:'Hill', uname:'khillca', _id: 100}, 'vB');
  // var v2 = gremlin.g.addVertex({fname:'Kevin', lname:'Hill', uname:'kivo360', _id: 101}, 'vC');
  // gremlin.g.addEdge(v1, v2, 'family' , { weight: '0.75f' });
  var helpme = gremlin.g.v(12).out();
  console.log(helpme)
  // 3. Send script for execution, and return a response with the results (if any)
  gremlin.exec(function(err, response) {
    // console.log(response)
  })
});

I printed the attempted vertex and it gives me results as if it were a query.

{ gremlin: 
   { script: 'g.v(12).out()',
     params: {},
     gRex: 
      { defaultOptions: [Object],
        options: [Object],
        resultFormatter: {},
        argumentHandler: [Object],
        T: [Object],
        Contains: [Object],
        Vertex: [Object],
        Edge: [Object],
        String: [Object],
        Integer: [Object],
        Geoshape: [Object],
        Direction: [Object],
        TitanKey: [Object],
        TitanLabel: [Object],
        ClassTypes: [Object],
        fetchHandler: [Function] },
     argumentHandler: { options: undefined } } }

How do I do a query that finds a given vertex?

from grex.

celrenheit avatar celrenheit commented on September 17, 2024

Well, it is a query, you have to execute it to get some results.

  var helpme = gremlin.g.v(1).out();
  console.log(helpme); // Give you a "query" object 

  helpme.gremlin.exec(function(err, response) {
    console.log(response); // And here is the response
  })

from grex.

jbmusso avatar jbmusso commented on September 17, 2024

Yup, it is indeed a query that needs to be executed first (= sent to Rexster over HTTP). gRex is an asynchronous library in which all gremlin instructions are appended and sent in one single script. Although bits of Gremlin Groovy scripts are added synchronously, you need to call .exec() or .fetch() in order to retrieve the results asynchronously.

Make sure the query defined in var helpme is executed in the callback passed to gremlin.exec(), or you will most likely get blank results.

Note that you might find valuable to use a Promise library in your code, such as Q, in order to reduce the callback hell.

from grex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.