Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example using graphs, vertices and edges #407

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tjoubert marked this conversation as resolved.
Show resolved Hide resolved
});
```

### 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