From 0d9a82efe501a28bcfc900c730111b598626da43 Mon Sep 17 00:00:00 2001 From: tjoubert Date: Mon, 15 Aug 2022 11:33:02 +0400 Subject: [PATCH] Added example using graphs, vertices and edges --- readme.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/readme.md b/readme.md index bb7ee42c..a031f52f 100644 --- a/readme.md +++ b/readme.md @@ -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) @@ -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 + { + new EdgeDefinition + { + From = new string[] { fromClx }, + To = new string[] { toClx }, + Collection = edgeClx + } + } + }); + + // Create a document in the Adults vertex collection + PostDocumentResponse fromResponse = await + adb.Document.PostDocumentAsync( + fromClx, + new { Name = "John Doe" }); + + // Create a document in the Students vertex collection + PostDocumentResponse toResponse = await + adb.Document.PostDocumentAsync( + 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.