npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@inferagraph/gremlin

v0.2.4

Published

Apache TinkerPop Gremlin datasource for InferaGraph

Readme

@inferagraph/gremlin

Gremlin datasource for @inferagraph/core. Targets the Gremlin protocol — works against any TinkerPop-compatible server, including Apache TinkerPop and Azure Cosmos DB Gremlin API.

Installation

pnpm add @inferagraph/gremlin @inferagraph/core

Migrating from @inferagraph/gremlin-datasource

The package was renamed from @inferagraph/gremlin-datasource to @inferagraph/gremlin in 0.2.0. The class was also renamed from GremlinDatasource to GremlinDataSource (PascalCase S) and a new gremlinDataSource(...) factory is the recommended on-ramp.

pnpm remove @inferagraph/gremlin-datasource
pnpm add @inferagraph/gremlin
- import { GremlinDatasource } from '@inferagraph/gremlin-datasource';
- const datasource = new GremlinDatasource({ endpoint: 'wss://...' });
+ import { gremlinDataSource } from '@inferagraph/gremlin';
+ const datasource = gremlinDataSource({ endpoint: 'wss://...' });

The class is still exported as the escape hatch:

import { GremlinDataSource } from '@inferagraph/gremlin';
const datasource = new GremlinDataSource({ endpoint: 'wss://...' });

Quick start

import { gremlinDataSource } from '@inferagraph/gremlin';

const datasource = gremlinDataSource({
  endpoint: 'wss://your-gremlin-server:443/',
});

await datasource.connect();
const graph = await datasource.getInitialView({ limit: 50 });
await datasource.disconnect();

Configuration

GremlinDataSourceConfig options:

| Option | Type | Description | | ----------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | | endpoint | string | Gremlin server WebSocket URL (wss://host:port/). Required. | | key | string | Auth key. Required for Cosmos DB; omit for an unauthenticated TinkerPop server. | | database | string | Cosmos DB database id. Used in the SASL username /dbs/<database>/colls/<container>. | | container | string | Cosmos DB container (graph) id. | | ssl | boolean | Enable TLS (rarely needed — wss:// already enables it). | | poolSize | number | Connection pool size hint. | | getCompositeKey | (id: string) => string \| [string, string] | Map a logical vertex id to the value(s) passed to g.V(...). Default: identity. See Composite keys. | | getType | (vertex: GremlinVertex) => string \| undefined | Resolve the semantic type of a vertex. Default: v.label. See Vertex type resolution. | | nameProperty | string | Vertex property used for search() and filter({ search }). Default: 'name'. See Name property. |

Composite keys (Cosmos DB)

Cosmos DB Gremlin containers are partitioned. Looking a vertex up by id alone does not work — you must pass the partition value too, in the form g.V(['<partitionValue>', '<id>']).

Configure getCompositeKey to translate logical ids into the tuples Cosmos needs. The library uses this everywhere a vertex is identified — getNode, getNeighbors, getContent, the path traversal in findPath, and the bulk edge fetches.

// Cosmos with partitionKey == id (the simplest scheme — what Bible Graph uses):
gremlinDataSource({
  endpoint: 'wss://my-cosmos.gremlin.cosmos.azure.com:443/',
  key: process.env.COSMOS_KEY,
  database: 'mydb',
  container: 'mygraph',
  getCompositeKey: (id) => [id, id],
});

// Cosmos with a partition value derived from the id:
gremlinDataSource({
  // ...endpoint, key, database, container...
  getCompositeKey: (id) => [getPartitionFor(id), id],
});

// Apache TinkerPop / unpartitioned: omit getCompositeKey entirely.
gremlinDataSource({ endpoint: 'wss://localhost:8182/' });

The library does not bake in any partition scheme. Every host-specific mapping is supplied via this option.

Vertex type resolution

By TinkerPop convention, the vertex label IS the type — addV('person') makes the vertex a person. Some hosts use a single label for every vertex and store the actual type in a property instead. getType lets such hosts tell the library where to find the real type.

// Default behavior — equivalent to NOT supplying getType:
gremlinDataSource({
  endpoint,
  getType: (v) => v.label,
});

// Host stores type in a `type` property (every vertex has the same label):
gremlinDataSource({
  endpoint,
  getType: (v) => {
    const t = v.properties?.type as Array<{ value?: unknown }> | undefined;
    return (t?.[0]?.value as string | undefined) ?? v.label;
  },
});

If getType returns undefined, the library falls back to v.label.

GremlinVertex is exported for typing custom resolvers:

import type { GremlinVertex } from '@inferagraph/gremlin';

Name property

search(query) and filter({ search }) issue g.V().has('<nameProperty>', TextP.containing(query)). By default <nameProperty> is 'name' — override when your vertices store the searchable display name on a different property.

// Default — searches the `name` property:
gremlinDataSource({ endpoint });

// Host whose vertices use `title` as the display name:
gremlinDataSource({ endpoint, nameProperty: 'title' });

Usage

await datasource.connect();

const graph     = await datasource.getInitialView({ limit: 50 });
const node      = await datasource.getNode('some-vertex-id');
const neighbors = await datasource.getNeighbors('some-vertex-id', 2);
const path      = await datasource.findPath('alice', 'bob');
const results   = await datasource.search('search term');
const filtered  = await datasource.filter({ types: ['person'] });
const content   = await datasource.getContent('some-vertex-id');

await datasource.disconnect();

Cosmos DB Gremlin notes

  • Cosmos containers are partitioned. Always configure getCompositeKey.
  • The library uses the composite-key-safe traversal g.V(<keys>).bothE().dedup() for bulk edge fetches and filters dangling endpoints client-side, instead of the more obvious where(otherV().hasId(within(ids))). The latter is unreliable on Cosmos when <ids> is a list of partition tuples.
  • findPath terminates with has(T.id, toId) rather than hasId(toId). On Cosmos, T.id compares the document id (the second half of the composite key); on TinkerPop it compares the vertex id directly.

Compatibility

Tested against:

  • Apache TinkerPop (Gremlin Server)
  • Azure Cosmos DB Gremlin API

The library targets the Gremlin protocol, so it should work against any TinkerPop-compatible server. Hosts whose vertex shape diverges from the defaults can adapt via getCompositeKey and getType.

License

MIT