Comments (16)
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.
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?
from grex.
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.
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.
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.
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.
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.
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.
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.
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.
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.
It looks I can finally close this issue. @gulthor @celrenheit I appreciate both of your help. Thanks a lot.
from grex.
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:
—
Reply to this email directly or view it on GitHub
#30 (comment).
Jean-Baptiste
from grex.
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.
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.
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)
- Array arguments not parsed properly HOT 4
- Boolean parameters are converted to strings HOT 2
- Cannot perform Elasticsearch queries HOT 1
- isFloat() returns true for some GUIDs HOT 1
- Limit on the size of script is around 8K HOT 5
- Flowrank using Grex HOT 6
- Except/Retain Pattern HOT 4
- how can I addVertex only if not exists and addEdge only if not exists using grex script in one query for execute HOT 4
- How can I do Bulk insert using grex with titan ( for huge amount of vertex and edges) HOT 1
- Support for removeVertex HOT 1
- Passing array argument results in java class cast exception
- *Question Really* How Do I Send Parameters Into server-side script HOT 5
- Add custom error types when handling errors
- Consider dynamically adding steps with Gremlin.getStepNames()
- Vertex returned server-side script can't be used in a transaction
- Titan 0.9 and Tinkerpop 3 HOT 3
- Replication HOT 1
- setProperty() example? HOT 1
- javax.script.ScriptException with Object argument HOT 2
- Erratic api behavior, am I missing something? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grex.