Graphmind TypeScript SDK

0.8.6 · active · verified Wed Apr 22

The `graphmind-sdk` is a TypeScript/Node.js client library designed to facilitate interaction with the Graphmind high-performance graph database, which natively supports OpenCypher. As of version 0.8.6, the SDK provides a comprehensive API for executing Cypher queries, managing graph schemas, performing health checks, and interacting with multi-tenant graph namespaces. It maintains a relatively active release cadence, frequently publishing patch versions. Key features include robust methods for standard query execution, schema introspection, query profiling, and an experimental natural language to Cypher (NLQ) translation capability. The SDK differentiates itself through its direct integration with Graphmind's performance optimizations and its support for distinct graph namespaces, enabling robust multi-tenancy scenarios.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a Graphmind client, demonstrates creating and querying data using Cypher, fetches the database schema, and shows how to configure a client with an authentication token from environment variables.

import { GraphmindClient } from 'graphmind-sdk';

async function runExample() {
  const client = new GraphmindClient({ url: 'http://localhost:8080' });

  try {
    // Create data (semicolons separate multiple statements)
    console.log('Creating initial data...');
    await client.query(`
      CREATE (a:Person {name: "Alice", age: 30});
      CREATE (b:Person {name: "Bob", age: 25});
      MATCH (a:Person {name: "Alice"}), (b:Person {name: "Bob"})
      CREATE (a)-[:KNOWS]->(b)
    `);
    console.log('Initial data created.');

    // Or use shared variables (no semicolons needed)
    console.log('Creating more data...');
    await client.query(`
      CREATE (c:Person {name: "Charlie", age: 35})
      CREATE (d:Person {name: "Diana", age: 28})
      CREATE (c)-[:KNOWS {since: 2023}]->(d)
    `);
    console.log('More data created.');

    // Query existing data
    console.log('Querying all persons...');
    const result = await client.query('MATCH (n:Person) RETURN n.name, n.age ORDER BY n.name');
    console.log('Query Result:', result);

    // Get schema introspection
    console.log('Fetching database schema...');
    const schema = await client.schema();
    console.log('Database Schema:', JSON.stringify(schema, null, 2));

    // Example with authentication using environment variable
    const authenticatedClient = new GraphmindClient({
      url: 'http://localhost:8080',
      token: process.env.GRAPHMIND_TOKEN ?? '', // Ensure GRAPHMIND_TOKEN env var is set
    });
    console.log('Checking authenticated client status...');
    const status = await authenticatedClient.status();
    console.log('Authenticated Client Status:', status);

  } catch (error) {
    console.error('An error occurred:', error.message);
    if (error.response) {
        console.error('Server response data:', error.response.data);
    }
  }
}

runExample().catch(console.error);

view raw JSON →