My presentation from Node Interactive 2016. It shows how you can use the ibm-graph-client module to connect and work with graph using IBM Graph http://www.ibm.com/analytics/us/en/technology/cloud-data-services/graph/
5. INIT SESSION
# Change the credentials to reflect your `apiURL`, `username`, and `password` and test the code in your instance.
{
"credentials": {
"apiURL": "https://ibmgraph-alpha.ng.bluemix.net/a261eac3-6956-4185-a789-8e24c475e89b/g",
"username": "575fd2b0-c011-4b94-82cf-43244b44f3a8",
"password": "aca0d011-26f5-485d-a446-182750278a27"
}
};
var ibmGraph= require('ibm-graph-client');
var g = new ibmGraph(instance.credentials);
g.session(function(err, data) {
if (err) {
console.log(err);
} else {
g.config.session = data;
console.log("Your session token is " + data);
}
});
6. CREATE A GRAPH
var graph; // graph name
g.graphs().create(function(err, data){
if (err) {
console.log("Something went wrong: ");
console.log(err);
} else {
graph = data.graphId;
console.log('Graph created: ' + data.graphId);
}
});
9. ADD A SCHEMA
#Point your config to the new graph you just created
g.config.url = g.config.url.substr(0, g.config.url.lastIndexOf('/') + 1) + graph;
g.schema().set(schema, function(err, data){
if (err) {
console.log(err);
}
console.log(JSON.stringify(data));
});
10. CREATE SOME VERTEXES AND EDGES
gremlin = {
gremlin: "
def david = graph.addVertex(T.label, 'person', 'name', 'David', 'verified', false);
def browniesTweet = graph.addVertex(T.label, 'tweet', 'tweet', 'I love brownies #baking @Joseph', 'sentiment', 'loving', 'tone', 'e
david.addEdge('tweets', browniesTweet);
browniesTweet.addEdge('hashes', bakingHashtag);
browniesTweet.addEdge('mentions', joseph);
",
bindings: {}
}
g.gremlin(gremlin, function(err,data){
if (err) {
console.log(err);
}
console.log(JSON.stringify(data));
});