tiger_graph

A Dart wrapper that streamlines connection between a TigerGraph cloud instance and Flutter. Essentially, all the communication between Flutter and TigerGraph is done through REST. This package is a simply wrapper to remove the redundancy and time of writing http requests manually.

Getting Started

The main class is GraphClient, and it essentially handles the communication between TigerGraph and your requests. Whenever a GraphClient is initialized, it automatically generates a new auth token to communicate with TigerGraph servers. My recommendation is to have one GraphClient through out the app and access that GraphClient to perform actions.

Getting a Vertex and Edge


//Server for instance is like this: 'fraud-det.i.tgcloud.us:9000'
GraphClient graphClient = await GraphClient.getInstance({Your Secret}, {Your Graph Name}, {Your Server Name});

/*this is the information about the vertex need to get it. In order to get all vertices of a certain Vertex Type
simply set 'vId': ''
*/

Map vertex = {'vType': 'Person', 'vId': '90'};

//getting the vertex data
Map data = graphClient.getVertex(vertex);

// In order to customize the edges we recieve, we can pass optional args
Map fromVertex = {'vType': 'Person', 'vId': '90'};

//grab all edges stemming from the vertex

Map data = await graphClient.getEdge(fromVertex);

//grab all edges of a certain edge type stemming from the vertex

Map data = await graphClient.getEdge(fromVertex, edgeType: 'LIKES');

//grab the edge based on edgeType and ending vertex

Map toVertex = {'vType': 'Person', 'vId': '76'};
Map data = await graphClient.getEdge(fromVertex, edgeType: 'LIKES', toVertex: toVertex);

Deleting vertices and Edges


//Deleting is very similar to getting vertices and edges

//TigerGraph handles deleting vertices and edges that do not exist very well, so no errors should occur

Map vertex = {'vType': 'Person', 'vId': '90'};

await graphClient.deleteVertex(vertex); //will give a Future<String> for confirmation

Map fromVertex  = {'vType': 'Person', 'vId': '90'};

//WARNING: this will delete all edges stemming from the fromVertex similar to how getEdge() grabs all edges
// The code will immediately stop that from happening, but if you do want to still delete pass in the optional arg override = 'DELETE'

await graphClient.deleteEdge(fromVertex); //CODE WILL STOP THIS FROM DELETING ALL EDGES

await graphClient.deleteEdge(fromVertex, override:'DELETE'); //CODE WILL DELETE ALL EDGES

//The code below will delete all edges of given edgeType similar to getEdge() gets all edges of given edgeType

await graphClient.deleteEdge(fromVertex, edgeType: 'LIKES');

//The code below will delete the edge between 2 vertices

Map toVertex = {'vType': 'Person', 'vId': '76'};

await graphClient.deleteEdge(fromVertex, edgeType: 'LIKES', toVertex:toVertex);

Upserting Data


//Typically it is recommend to upsert data with a WriteBatch since it upserts a bunch of data in one request

//For example

final batch = graphClient.createWriteBatch();

//the attrs key is essentially the attributes of the vertex, you can ignore having to provide vId or type
//put in the attrs with the attribute name as key and attribute value as value
Map v1 = {'vType': 'Person', 'vId': '55', 'attrs':{'name': 'Jenny'}};
Map v2 = {'vType': 'Person', 'vId': '51', 'attrs':{'name': 'Peter'}};

batch.upsertVertex(v1);
batch.upsertVertex(v2);

//upserting an edge is similar, must provide the fromVertex, toVertex, edgeName and edge attributes
batch.upsertEdge(v1, v2, 'LIKES', {}); //pass in attributes the same way as we did for vertices

//once ready to post the data commit
await batch.commit();

Calling Written Queries


//In order to call written queries, simply use the callQuery()

await graphClient.callQuery({you query name}, {your query args});

//the query args is a map of parameters that the query takes
//the parameter name will be the key and the the value that is passed shall be the value in the map

//For example

await graphClient.callQuery("Hello Neighbors", {'personId': '55'});

//The code above will call the written query "Hello Neighbors" with the Vertex<Person> parameter "personId"

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Libraries

exceptions
tiger_graph