Skip to content

Commit

Permalink
Make cluster-only graph properties optional in response.
Browse files Browse the repository at this point in the history
fix #303
  • Loading branch information
DiscoPYF committed Nov 18, 2020
1 parent e620f14 commit 0340130
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
21 changes: 15 additions & 6 deletions arangodb-net-standard.Test/GraphApi/GraphApiClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public async Task GetGraphsAsync_ShouldSucceed()
var graph = graphsResult.Graphs.First(x => x._key == _fixture.TestGraph);
Assert.NotEmpty(graph.EdgeDefinitions);
Assert.Empty(graph.OrphanCollections);
Assert.Equal(1, graph.NumberOfShards);
Assert.Equal(1, graph.ReplicationFactor);
Assert.False(graph.IsSmart);
Assert.Equal(_fixture.TestGraph, graph._key);
Assert.Equal("_graphs/" + _fixture.TestGraph, graph._id);
Assert.NotNull(graph._rev);

// cluster-only values, not returned for a single server since 3.7
Assert.False(graph.NumberOfShards.HasValue);
Assert.False(graph.ReplicationFactor.HasValue);
Assert.False(graph.IsSmart.HasValue);
}

[Fact]
Expand Down Expand Up @@ -93,12 +95,14 @@ public async Task GetGraphAsync_ShouldSucceed()
Assert.Equal("_graphs/" + _fixture.TestGraph, response.Graph._id);
Assert.NotEmpty(response.Graph.EdgeDefinitions);
Assert.Empty(response.Graph.OrphanCollections);
Assert.Equal(1, response.Graph.NumberOfShards);
Assert.Equal(1, response.Graph.ReplicationFactor);
Assert.False(response.Graph.IsSmart);
Assert.Equal(_fixture.TestGraph, response.Graph._key);
Assert.Equal("_graphs/" + _fixture.TestGraph, response.Graph._id);
Assert.NotNull(response.Graph._rev);

// cluster-only values, not returned for a single server since 3.7
Assert.False(response.Graph.NumberOfShards.HasValue);
Assert.False(response.Graph.ReplicationFactor.HasValue);
Assert.False(response.Graph.IsSmart.HasValue);
}

[Fact]
Expand Down Expand Up @@ -294,6 +298,11 @@ public async Task PostEdgeDefinitionAsync_ShouldSucceed()
Assert.NotNull(response.Graph._rev);
Assert.False(response.Graph.IsSmart);
Assert.Empty(response.Graph.OrphanCollections);

// cluster-only values, not returned for a single server since 3.7
Assert.False(response.Graph.NumberOfShards.HasValue);
Assert.False(response.Graph.ReplicationFactor.HasValue);
Assert.False(response.Graph.IsSmart.HasValue);
}

[Fact]
Expand Down
7 changes: 5 additions & 2 deletions arangodb-net-standard/GraphApi/GraphApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public GraphApiClient(IApiClientTransport transport, IApiClientSerialization ser
/// Creates a new graph in the graph module.
/// POST /_api/gharial
/// </summary>
/// <remarks>
/// The creation of a graph requires the name of the graph and a definition of its edges.
/// </remarks>
/// <param name="postGraphBody">The information of the graph to create.</param>
/// <param name="query">Optional query parameters of the request.</param>
/// <returns></returns>
Expand Down Expand Up @@ -370,7 +373,7 @@ public virtual async Task<PostEdgeResponse<T>> PostEdgeAsync<T>(
string collectionName,
T edge,
PostEdgeQuery query = null,
ApiClientSerializationOptions serializationOptions = null)
ApiClientSerializationOptions serializationOptions = null)
{
var content = GetContent(edge, serializationOptions);

Expand Down Expand Up @@ -735,7 +738,7 @@ public virtual async Task<PutEdgeResponse<T>> PutEdgeAsync<T>(
uri += "?" + query.ToQueryString();
}

var content = GetContent(edge, new ApiClientSerializationOptions(false,false));
var content = GetContent(edge, new ApiClientSerializationOptions(false, false));
using (var response = await _transport.PutAsync(uri, content))
{
if (response.IsSuccessStatusCode)
Expand Down
20 changes: 16 additions & 4 deletions arangodb-net-standard/GraphApi/Models/GraphResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ public class GraphResult
public string SmartGraphAttribute { get; set; }

/// <summary>
/// The replication factor used for every new collection in the graph.
/// The replication factor used for every new collection in the graph (Enterprise Edition only).
/// </summary>
public int ReplicationFactor { get; set; }
/// <remarks>
/// Returned only in a cluster setup since ArangoDB 3.7,
/// as this property is not meaningful in a single server.
/// </remarks>
public int? ReplicationFactor { get; set; }

/// <summary>
/// A list of additional vertex collections.
Expand All @@ -50,12 +54,20 @@ public class GraphResult
/// <summary>
/// Number of shards created for every new collection in the graph.
/// </summary>
public int NumberOfShards { get; set; }
/// <remarks>
/// Returned only in a cluster setup since ArangoDB 3.7,
/// as this property is not meaningful in a single server.
/// </remarks>
public int? NumberOfShards { get; set; }

/// <summary>
/// Indicates whether the graph is a SmartGraph (Enterprise Edition only).
/// </summary>
public bool IsSmart { get; set; }
/// <remarks>
/// Returned only in a cluster setup since ArangoDB 3.7,
/// as this property is not meaningful in a single server.
/// </remarks>
public bool? IsSmart { get; set; }

/// <summary>
/// A list of definitions for the relations of the graph.
Expand Down
25 changes: 25 additions & 0 deletions arangodb-net-standard/GraphApi/Models/PostGraphBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,41 @@

namespace ArangoDBNetStandard.GraphApi.Models
{
/// <summary>
/// Represents a request body to create a named graph.
/// </summary>
/// <remarks>
/// The creation of a graph requires the name of the graph and a definition of its edges.
/// </remarks>
public class PostGraphBody
{
/// <summary>
/// Name of the graph.
/// </summary>
public string Name { get; set; }

/// <summary>
/// List of definitions for the relations of the graph.
/// </summary>
public List<EdgeDefinition> EdgeDefinitions { get; set; }

/// <summary>
/// (Optional) List of additional vertex collections.
/// Documents within these collections do not have edges within this graph.
/// </summary>
public List<string> OrphanCollections { get; set; }

/// <summary>
/// (Optional) Defines if the created graph should be smart (Enterprise Edition only).
/// </summary>
/// <remarks>
/// (cluster only)
/// </remarks>
public bool? IsSmart { get; set; }

/// <summary>
/// (Optional) Defines options for creating collections within this graph.
/// </summary>
public PostGraphOptions Options { get; set; }
}
}
12 changes: 10 additions & 2 deletions arangodb-net-standard/GraphApi/Models/PostGraphOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ public class PostGraphOptions
/// It is required if creating a SmartGraph.
/// Every vertex in this SmartGraph has to have this attribute.
/// Cannot be modified later.
/// (Enterprise Edition only).
/// </summary>
/// <remarks>
/// Only has effect in Enterprise Edition.
/// (cluster only)
/// </remarks>
public string SmartGraphAttribute { get; set; }

/// <summary>
/// The number of shards that is used for every collection within this graph.
/// Cannot be modified later.
/// </summary>
/// <remarks>
/// (cluster only)
/// </remarks>
public int NumberOfShards { get; set; }

/// <summary>
/// The replication factor used when initially creating collections for this graph.
/// The replication factor used when initially creating collections for this graph
/// (Enterprise Edition only).
/// </summary>
/// <remarks>
/// (cluster only)
/// </remarks>
public int ReplicationFactor { get; set; }
}
}

0 comments on commit 0340130

Please sign in to comment.