SlideShare a Scribd company logo
1 of 11
Download to read offline
IBM-GRAPH-CLIENT
https://www.npmjs.com/package/ibm-graph-client
SIGN	UP	ON	BLUEMIX.NET	AND	LOOK	FOR	IBM
GRAPH
CREATE	AN	INSTANCE
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);
}
});
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);
}
});
GET	ALL	GRAPHS
g.graphs().get(function(err, data){
if (err) {
console.log(err);
}
console.log(data);
});
DEFINE	A	SCHEMA
var schema = {
"propertyKeys": [
{"name": "name", "dataType": "String", "cardinality": "SINGLE"},
],
"vertexLabels": [
{"name": "person"},
],
"edgeLabels": [
{"name": "tweets", "multiplicity": "MULTI"},
],
"vertexIndexes": [
{"name": "vByName", "propertyKeys": ["name"], "composite": true, "unique": true},
],
"edgeIndexes" :[
{"name": "eByTime", "propertyKeys": ["time"], "composite": true, "unique": false}
]
}
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));
});
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));
});
QUERY	THE	GRAPH
gremlin = {
"gremlin": "graph.traversal().V().hasLabel('person').has('name', name).outE('favorites').inV();",
"bindings": { "name": "Kamal" }
}
g.gremlin(gremlin, function(err,data){
if (err) {
console.log('Error: ' + err);
}
console.log(JSON.stringify(data));
});

More Related Content

Similar to Use IBM Graph from NodeJS

Manageable data pipelines with airflow (and kubernetes) november 27, 11 45 ...
Manageable data pipelines with airflow (and kubernetes)   november 27, 11 45 ...Manageable data pipelines with airflow (and kubernetes)   november 27, 11 45 ...
Manageable data pipelines with airflow (and kubernetes) november 27, 11 45 ...
Jarek Potiuk
 

Similar to Use IBM Graph from NodeJS (20)

Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기Node.js API 서버 성능 개선기
Node.js API 서버 성능 개선기
 
AWS CloudFormation Intrinsic Functions and Mappings
AWS CloudFormation Intrinsic Functions and Mappings AWS CloudFormation Intrinsic Functions and Mappings
AWS CloudFormation Intrinsic Functions and Mappings
 
AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...
AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...
AWS Study Group - Chapter 03 - Elasticity and Scalability Concepts [Solution ...
 
SETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventuresSETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventures
 
Spark Jobserver
Spark JobserverSpark Jobserver
Spark Jobserver
 
Super-NetOps Source of Truth
Super-NetOps Source of TruthSuper-NetOps Source of Truth
Super-NetOps Source of Truth
 
GraphQL & Prisma from Scratch
GraphQL & Prisma from ScratchGraphQL & Prisma from Scratch
GraphQL & Prisma from Scratch
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
 
GraphQL IN Golang
GraphQL IN GolangGraphQL IN Golang
GraphQL IN Golang
 
Introduce to Spark sql 1.3.0
Introduce to Spark sql 1.3.0 Introduce to Spark sql 1.3.0
Introduce to Spark sql 1.3.0
 
Docker remote-api
Docker remote-apiDocker remote-api
Docker remote-api
 
Manageable data pipelines with airflow (and kubernetes) november 27, 11 45 ...
Manageable data pipelines with airflow (and kubernetes)   november 27, 11 45 ...Manageable data pipelines with airflow (and kubernetes)   november 27, 11 45 ...
Manageable data pipelines with airflow (and kubernetes) november 27, 11 45 ...
 
Spark Sql for Training
Spark Sql for TrainingSpark Sql for Training
Spark Sql for Training
 
QConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações WebQConSP 2015 - Dicas de Performance para Aplicações Web
QConSP 2015 - Dicas de Performance para Aplicações Web
 
api-platform: the ultimate API platform
api-platform: the ultimate API platformapi-platform: the ultimate API platform
api-platform: the ultimate API platform
 
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
Nagios Conference 2013 - Troy Lea - Leveraging and Understanding Performance ...
 
Running Docker on AWS
Running Docker on AWSRunning Docker on AWS
Running Docker on AWS
 
Auto Scaling Groups
Auto Scaling GroupsAuto Scaling Groups
Auto Scaling Groups
 
Super-NetOps Source of Truth
Super-NetOps Source of TruthSuper-NetOps Source of Truth
Super-NetOps Source of Truth
 
[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6[W3C HTML5 2016] Angular + ES6
[W3C HTML5 2016] Angular + ES6
 

Recently uploaded

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Recently uploaded (20)

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 

Use IBM Graph from NodeJS

  • 1.
  • 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); } });
  • 7. GET ALL GRAPHS g.graphs().get(function(err, data){ if (err) { console.log(err); } console.log(data); });
  • 8. DEFINE A SCHEMA var schema = { "propertyKeys": [ {"name": "name", "dataType": "String", "cardinality": "SINGLE"}, ], "vertexLabels": [ {"name": "person"}, ], "edgeLabels": [ {"name": "tweets", "multiplicity": "MULTI"}, ], "vertexIndexes": [ {"name": "vByName", "propertyKeys": ["name"], "composite": true, "unique": true}, ], "edgeIndexes" :[ {"name": "eByTime", "propertyKeys": ["time"], "composite": true, "unique": false} ] }
  • 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)); });
  • 11. QUERY THE GRAPH gremlin = { "gremlin": "graph.traversal().V().hasLabel('person').has('name', name).outE('favorites').inV();", "bindings": { "name": "Kamal" } } g.gremlin(gremlin, function(err,data){ if (err) { console.log('Error: ' + err); } console.log(JSON.stringify(data)); });