Skip to content

Instantly share code, notes, and snippets.

View Ramko9999's full-sized avatar
🎯
Focusing

Ramko9999

🎯
Focusing
View GitHub Profile
@Ramko9999
Ramko9999 / init.dart
Last active February 21, 2020 03:17
TigerGraph Flutter Medium
final client = await GraphClient.getInstance("YOUR TOKEN","YOUR GRAPH NAME", "YOUR SERVER INFORMATION");
/*
For example, if my domain was "https://flutter-test.i.tgcloud.io:14240/#/home" with my graph name called "demo_graph"
Here is what my client paramters would look like
*/
String token = "12345678900";
final client = await GraphClient.getInstance(token, "demo_graph", "flutter-test.i.tgcloud.io:9000");
@Ramko9999
Ramko9999 / ret.dart
Created February 21, 2020 02:04
Edge Retrieval
Map result = await client.getEdge("SOURCE VERTEX", "EDGE NAME", "TARGET VERTEX (OPTIONAL)");
/*
For example, consider I have in Graph Schema the Vertex Person has an Edge to Vertex Phone called "HAS_PHONE"
If I wanted to get that edge, here is how that would look.
*/
Vertex source = Vertex("Person", "1");
Vertex target = Vertex("Phone", "612-391-2389");
@Ramko9999
Ramko9999 / del_vert.dart
Created February 21, 2020 02:10
Deleting Vertices
/*
Deleting a Vertex is the same as getting Vertices.
*/
await client.deleteVertex("THE VERTEX OBJECT");
/*
If I wanted to delete a Vertex of type "Person" with id "91", here is
how I would do it:
*/
/*
Here is how we would delete the "HAS_PHONE" edge shown earlier.
*/
Vertex source = Vertex("Person", "1");
Vertex target = Vertex("Phone", "612-391-2389");
String edge = "HAS_PHONE";
await client.deleteEdge(source, edge, target);
/*
/*
Calling Queries
*/
Map result = await client.callQuery("QUERY NAME", "ARGUMENTS");
/*
The Arguments is essentially the parameters for the TigerGraph query.
For example, consider I wrote a Query called "findPhones" which returns all the phones
belonging to a person.
/*
This is strictly for upserting a couple of Vertices or Edges.
If you want to upsert many Vertices or Edges in bulk, we will cover that in
the next code snippet.
*/
/*
Here is the format for the Upserting Vertices
*/
@Ramko9999
Ramko9999 / writebatch.dart
Created February 21, 2020 02:54
WriteBacth
/*
To create a write batch, simply call GraphClient.createWriteBatch()
*/
final writeBatch = client.createWriteBatch();
/*
We can essentially upsert as many vertices or edges as we want, and then when we are ready,
we can send all our upserted vertices and edges in one request.
/*
We can do many more vertex attribute operations using the FieldValue class.
*/
//For Incrementing a Number Vertex
FieldValue.increment("THE NUMBER");
//Doing the "OR" operation or "||" on boolean values with new value
FieldValue.logicalOr("THE BOOLEAN");
@Ramko9999
Ramko9999 / get_vertex_dat.dart
Created February 21, 2020 03:11
get_vertex_data
/*
GETTING VERTEX DATA
*/
Map result = await client.getVertex(Vertex("product", "BELTS"));
/*The return object will be the Json decoded standard tigerGraph response, thus it will be a map.
For example, here is what result will be:
{version:
/*
Before, we attempt to retrieve any vertices, we must first create a Vertex() object that we can pass in as a paramter.
*/
Vertex v1 = Vertex("VERTEX TYPE", "VERTEX ID", "VERTEX ATTRIBUTES (OPTIONAL)");
Vertex siteVertex = Vertex("site", "site91"); //example