Skip to content

Instantly share code, notes, and snippets.

@Ramko9999
Created February 21, 2020 02:46
Show Gist options
  • Save Ramko9999/9710c2b8e4102de03a3e02ec28b83348 to your computer and use it in GitHub Desktop.
Save Ramko9999/9710c2b8e4102de03a3e02ec28b83348 to your computer and use it in GitHub Desktop.
/*
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
*/
await client.upsertVertex("YOUR VERTEX OBJECT WITH ATTRIBUTES");
/*
Here is the format for Upserting Edges
*/
await client.upsertEdge("SOURCE VERTEX", "TARGET VERTEX", "EDGE NAME", "EDGE ATTRIBUTES");
/*
Whenever we passed in a Vertex Object previously, we did not pass in the optional argument attributes. This time
we will have to pass that in.
Consider for example, that the "Person" vertex we had contained fields: ["name", "age"]
Here is how we would create the Vertex Object
*/
Vertex newPerson = Vertex("Person", "100", attributes: {"name": "James", "age": 26});
/*
All we have to then do is call the upsertVertex() for GraphClient
*/
await client.upsertVertex(newPerson);
/*
Lets move on to upserting an edge. Since we are upserting an edge, the attributes parameter for "SOURCE VERTEX" and "TARGET VERTEX"
is optional again. We do however will need to put the attributes of edge if it has any.
We would create the attributes the same way we created the attributes for the Vertices.
*/
Vertex source = Vertex("Person", "100");
Vertex target = Vertex("Phone", "877-876-9971");
String edge = "HAS_PHONE";
Map attributes = {}; //suppose our edge has no attributes
await client.upsertEdge(source, target, edge, attributes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment