Help us shape the future of Go! Take the 2026 Go Developer Survey

gremlin

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package gremlin is an in-process Apache TinkerPop Gremlin server over the shared openCypher property graph.

It speaks the Gremlin Server WebSocket protocol (GraphSON v2/v3 and GraphBinary v1) and the HTTP endpoint, and runs Gremlin scripts and bytecode against the same nodes and relationships as openCypher and Bolt.

Index

Constants

View Source
const (
	CodeMalformedQuery      = "MalformedQueryException"
	CodeInvalidParameter    = "InvalidParameterException"
	CodeConstraintViolation = "ConstraintViolationException"
	CodeUnsupported         = "UnsupportedOperationException"
	CodeTimeLimit           = "TimeLimitExceededException"
	CodeCancelled           = "CancelledByUserException"
	CodeInternal            = "InternalFailureException"
	CodeUnauthorized        = "AccessDeniedException"
)

Neptune error codes returned by the HTTP endpoint; WebSocket clients get the Gremlin Server status instead.

View Source
const (
	StatusSuccess          = 200
	StatusNoContent        = 204
	StatusPartial          = 206
	StatusUnauthorized     = 401
	StatusInvalidRequest   = 499
	StatusServerError      = 500
	StatusScriptEvalError  = 597
	StatusServerTimeout    = 598
	StatusSerializationErr = 599
)

Gremlin Server response status codes.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	ID       string
	Label    string
	OutID    string
	OutLabel string
	InID     string
	InLabel  string
}

Edge is a detached edge reference as returned to clients.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine runs Gremlin against an openCypher graph.

func NewEngine

func NewEngine() *Engine

NewEngine returns an engine with every supported step registered.

func (*Engine) Bytecode

func (e *Engine) Bytecode(ctx context.Context, g *opencypher.Graph, tr *Traversal) ([]any, error)

Bytecode runs a traversal that arrived as bytecode.

func (*Engine) Eval

func (e *Engine) Eval(ctx context.Context, g *opencypher.Graph, script string, bindings map[string]any) ([]any, error)

Eval parses and runs a Gremlin script.

type Error

type Error struct {
	Code   string
	Detail string
	Status int
}

Error is a query failure carrying the Gremlin Server status and the Neptune error code.

func AsError

func AsError(err error) (*Error, bool)

AsError extracts an *Error from err.

func (*Error) Error

func (e *Error) Error() string

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is an insertion-ordered map whose keys may be any value.

func NewMap

func NewMap() *Map

NewMap returns an empty Map.

func (*Map) Entry

func (m *Map) Entry(i int) (any, any)

Entry returns the i-th key and value.

func (*Map) Get

func (m *Map) Get(k any) (any, bool)

Get returns the value for k.

func (*Map) Len

func (m *Map) Len() int

Len is the number of entries.

func (*Map) Put

func (m *Map) Put(k, v any)

Put sets key to val, replacing an equal key.

type Options

type Options struct {
	// Track registers a running query and returns its cancellable context and a finish callback.
	Track   func(parent context.Context, query string) (context.Context, func())
	Timeout time.Duration
}

Options configures a Server.

type Path

type Path struct {
	Labels  [][]string
	Objects []any
}

Path is a traversal path.

type Pred

type Pred struct {
	Op       string
	Args     []any
	Children []Pred
}

Pred is a P or TextP predicate tree.

type Prop

type Prop struct {
	Owner any
	Val   any
	Key   string
	VP    bool
}

Prop is a vertex property, a meta view of an edge property, or a property key/value.

func (*Prop) ID

func (p *Prop) ID() int64

ID is the stable, derived id of a vertex property.

type Property

type Property struct {
	Val any
	Key string
	ID  int64
	VP  bool
}

Property is a detached property as returned to clients.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves Gremlin over WebSocket and HTTP against one graph.

func NewServer

func NewServer(ctx context.Context, g *opencypher.Graph, opt Options) *Server

NewServer returns a server whose WebSocket connections close when ctx is done.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP upgrades WebSocket requests and answers HTTP queries.

type Set

type Set []any

Set is an ordered collection with set semantics on the wire.

type Step

type Step struct {
	Name string
	Args []any
	Mods []Step
	// Pre marks a modulator written before its step (until/emit before repeat).
	Pre bool
}

Step is one step with its arguments and the modulators ("by", "from", modTimes, ...) that follow it.

type Stmt

type Stmt struct {
	Tr   *Traversal
	Term string
	N    int
}

Stmt is one script statement: a traversal and the terminal call that ends it.

func ParseScript

func ParseScript(src string, bindings map[string]any) ([]Stmt, error)

ParseScript parses a Gremlin-Groovy script made of g.<traversal> statements.

type Token

type Token struct {
	Kind string
	Name string
}

Token is a TinkerPop enum value such as T.id, Order.desc or Direction.OUT.

type Traversal

type Traversal struct {
	Steps []Step
}

Traversal is a parsed Gremlin traversal: the steps after g (or inside an anonymous __).

func (*Traversal) Mutates

func (t *Traversal) Mutates() bool

Mutates reports whether running the traversal can change the graph.

func (*Traversal) String

func (tr *Traversal) String() string

type Vertex

type Vertex struct {
	ID    string
	Label string
}

Vertex is a detached vertex reference as returned to clients.

type VertexRef

type VertexRef struct {
	ID string
}

VertexRef is a vertex or edge argument that arrived by id.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL