Skip to content

Gremlinq.Extensions

Gremlinq.Extensions.GroovyScripts

Includes CosmosDb provider packages

Purchasing this product also grants access to the CosmosDb provider packages for ExRam.Gremlinq 13 via the paid private NuGet feed. Transition details: CosmosDb provider packages transition.

Introduction

Gremlinq normally serializes queries as TinkerPop bytecode. Gremlinq.Extensions.GroovyScripts is for users who prefer sending raw Groovy strings instead — whether that is a personal preference or because they have an existing codebase of Groovy scripts to integrate. ExecuteGroovyScript<T>() on IGremlinQuerySource is the entry point. Results are deserialized through Gremlinq's standard pipeline, so you get a typed IAsyncEnumerable<T> back.

Three levels of API are provided:

  • Raw string — pass a Groovy expression directly. Convenient for static scripts, but never interpolate or concatenate external input into the string. The script is sent to the server and executed verbatim — a user-controlled value embedded in the string could alter the traversal or access data it should not, in the same way SQL injection works.
  • Bindings dictionary — pass variable values alongside the script as a Dictionary<string, object?>. The server substitutes the bindings before execution, keeping script text and data cleanly separated and eliminating injection risk.
  • Fluent builder — a C# lambda that gives you named GroovyVariable references, an interpolated string for the script body, and .Bind() calls to associate each variable with its value. Up to 256 variables are supported. Produces the same binding mechanism as the dictionary approach, expressed entirely in type-safe C#.

Setup

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

.NET CLI
dotnet add package Gremlinq.Extensions.GroovyScripts

# If IAsyncEnumerable extensions like ToArrayAsync are needed, add this package as well (unless already referenced):

dotnet add package System.Linq.Async

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

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

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

Usage examples

  • Raw Groovy string — use only for scripts with no external input:
C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

await source
    .ExecuteGroovyScript<Airport>("g.V().hasLabel('Airport').has('elevation', gt(1000))")
    .ToArrayAsync();
  • Bindings dictionary — the server substitutes each binding before execution, so external values never become part of the script text:
C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

await source
    .ExecuteGroovyScript<Airport>(
        "g.V().hasLabel(label).has(elevationProperty, gt(elevation))",
        new Dictionary<string, object?>
        {
            { "label", "Airport" },
            { "elevation", 1000 },
        })
    .ToArrayAsync();
  • Fluent builder — the same server-side binding mechanism, with named variables and compile-time safety instead of a stringly-typed dictionary:
C#
using static ExRam.Gremlinq.Core.GremlinQuerySource;

await source
    .ExecuteGroovyScript<Airport>((builder, label, elevationProperty, elevation) => builder
        .WithScript($"g.V().hasLabel({label}).has({elevationProperty}, gt({elevation}))")
        .Bind(label.To("Airport"))
        .Bind(elevationProperty.To("elevation"))
        .Bind(elevation.To(1000)))
    .ToArrayAsync();

Pricing

Developer Seats Price per seat (€) / year (excl. tax)
For the first 1 to 5 199.00
For the next 6 to 20 67.00
For the rest included

Need a bundled offer? Reach out at info@danielcweber.net.