Skip to content

Commit

Permalink
Merge pull request #407 from ArangoDB-Community/feature-3.8/DE-286-gr…
Browse files Browse the repository at this point in the history
…aph-get-started

Added example using graphs, vertices and edges
  • Loading branch information
tjoubert authored Oct 26, 2022
2 parents ba458b7 + 0d9a82e commit c9c0271
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A consistent, comprehensive, minimal driver for the [ArangoDB REST API](https://
- [Run an AQL query](#run-an-aql-query)
- [Patch a document](#patch-a-document)
- [Replace a document](#replace-a-document)
- [Example using graphs](#example-using-graphs)
+ [Serialization Options](#serialization-options)
+ [API Errors](#api-errors)
+ [Project Conventions](#project-conventions)
Expand Down Expand Up @@ -173,6 +174,59 @@ await adb.Document.PutDocumentAsync(
item);
```

#### Example using graphs

```csharp
//Example using graphs, vertices and edges
string graphName = "SchoolGraph";
string fromClx = "Adults";
string toClx = "Students";
string edgeClx = "Parents";

// Create a new graph
await adb.Graph.PostGraphAsync(new PostGraphBody
{
Name = graphName,
EdgeDefinitions = new List<EdgeDefinition>
{
new EdgeDefinition
{
From = new string[] { fromClx },
To = new string[] { toClx },
Collection = edgeClx
}
}
});

// Create a document in the Adults vertex collection
PostDocumentResponse<object> fromResponse = await
adb.Document.PostDocumentAsync<object>(
fromClx,
new { Name = "John Doe" });

// Create a document in the Students vertex collection
PostDocumentResponse<object> toResponse = await
adb.Document.PostDocumentAsync<object>(
toClx,
new { Name = "Jimmy Doe" });

// Create the edge Parent edge between the Adult (John Doe) and Child (Jimmy Doe)
var response = await adb.Graph.PostEdgeAsync(
graphName,
edgeClx,
new
{
_from = fromResponse._id,
_to = toResponse._id,
myKey = "parent1"
},
new PostEdgeQuery
{
ReturnNew = true,
WaitForSync = true
});
```

### Serialization Options

All API methods that support passing objects of user-specified data types have an optional method argument to pass in custom serialization options. These options can be used to control the behaviour of the underlying serializer implementation.
Expand Down

0 comments on commit c9c0271

Please sign in to comment.