Skip to content

Gremlinq.Extensions.Strategies   

Introduction

Gremlinq.Extensions.Strategies enhances Gremlinq with support for traversal strategies. Note, however, that not every graph database provider may support all TinkerPop strategies (especially CosmosDb only supports a very limited set of traversal strategies). Please consult the respective documentation of your graph database provider.

Supported strategies:

  • AdjacentToIncidentStrategy
  • ConnectiveStrategy
  • CountStrategy
  • EarlyLimitStrategy
  • EdgeLabelVerificationStrategy
  • ElementIdStrategy
  • FilterRankingStrategy
  • GraphFilterStrategy
  • HaltedTraverserStrategy
  • IdentityRemovalStrategy
  • IncidentToAdjacentStrategy
  • InlineFilterStrategy
  • LambdaRestrictionStrategy
  • LazyBarrierStrategy
  • MatchAlgorithmStrategy
  • MatchPredicateStrategy
  • OptionsStrategy
  • OrderLimitStrategy
  • PartitionStrategy
  • PathProcessorStrategy
  • PathProcessorStrategy
  • PathProcessorStrategy
  • ReadOnlyStrategy
  • RepeatUnrollStrategy
  • ReservedKeysVerificationStrategy
  • ReservedKeysVerificationStrategy
  • SubgraphStrategy
  • VertexProgramStrategy

Strategies supported on CosmosDb:

  • PartitionStrategy
  • ProjectionStrategy

Setup

After setting up our NuGet package server with your license key, add the package(s) to your project

.NET CLI
// For general TinkerPop strategy support
dotnet add package Gremlinq.Extensions.Strategies
.NET CLI
// For CosmosDb strategies
dotnet add package Gremlinq.Extensions.Strategies.CosmosDb

In your app's initial setup of IGremlinQuerySource, configure the environment and addd a call to AddStrategySupport, like shown below:

C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

// (Incomplete) example provider setup and Gremlinq.Extensions.Strategies setup
var source = g
    .UseGremlinServer<Vertex, Edge>(_ => _
        .AtLocalhost())
   .ConfigureEnvironment(env => env
        .AddStrategySupport());

For CosmosDb, AddCosmosDbStrategySupport must be called instead. It is not necessary to call both, AddCosmosDbStrategySupport and AddStrategySupport:

C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

// (Incomplete) example provider setup and Gremlinq.Extensions.Strategies setup    
var source = g
    .UseCosmosDb<Vertex, Edge>(_ => _
        .AtLocalhost())
   .ConfigureEnvironment(env => env
        .AddCosmosDbStrategySupport());

Usage example

  • General TinkerPop
C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

// Usage example:
await source
    .WithStrategy(SubgraphStrategy
        .Build()
        .Vertices(__ => __
            .Cast<Vertex>()
            .Where(x => x.Tenant == "tenantId"))
        .Create())
    .V();
  • CosmosDb
C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

// (Incomplete) example provider setup and Gremlinq.Extensions.Strategies.CosmosDb setup
var source = g
    .UseCosmosDb<Vertex, Edge>(_ => _
        .AtLocalhost())
   .ConfigureEnvironment(env => env
        .AddCosmosDbStrategySupport());

/* Usage example:
   Retrieve system properties as part of vertices and
   edges. Make sure that the entity classes in your
   project contain the respective properties with
   appropriate types and names, i.e.

   public class Vertex
   {
       public string? _Etag { get; set; }

       public string? _Self { get; set; }
   }*/

await source
    .WithStrategy(ProjectionStrategy
        .Build()
        .IncludeSystemProperties(SystemProperty._etag, SystemProperty._self)
        .Create())
    .V();

await source
    .WithStrategy(PartitionStrategy
        .Build()
        .PartitionKey("PartitionKey")
        .ReadPartitions("_partition_1")
        .Create())
    .V();

Further reading:

Traversal strategies
Access system document properties using Azure Cosmos DB