dgraph-io/dgraph-js

Official Dgraph JavaScript client

What it solves

Building a JavaScript application that needs to talk to Dgraph — a distributed graph database — requires a reliable client. This library removes the need to write low-level gRPC code yourself by providing a high-level API for schema management, transactions, queries, and mutations. It also handles connection details, authentication, and TLS so you can focus on your graph data.

How it works

The client communicates with a Dgraph cluster using gRPC. You connect using a connection string like dgraph://localhost:9080 or one that includes credentials, API keys, or TLS settings. It follows the design of the official Go client closely.

Key operations include:

  • Alter: change the schema or drop data using an Operation object.
  • Transactions: create read-only or best-effort transactions, commit or discard them explicitly.
  • Mutations: insert data as JSON or RDF N-Quads, optionally committing immediately or skipping index conflict checks.
  • Queries: run GraphQL± queries with variables, get JSON responses.
  • Upserts: combine a query and a mutation in one request, with optional conditional execution.
  • Multi-tenancy: log into a specific namespace using loginIntoNamespace.
  • Debug mode: print helpful debug messages during operations.
  • Headers: pass custom metadata like auth tokens to gRPC calls.

All client methods return Promises, and the library works with both JavaScript and TypeScript (with the help of type packages).

Who it’s for

Developers building Node.js applications that use Dgraph as their graph database. It suits anyone who needs to perform graph queries, manage schema, or run transactions from JavaScript, especially those already familiar with Dgraph’s query language and concepts.

Highlights

  • Official client maintained by Dgraph, ensuring compatibility with current server versions.
  • Built on gRPC for efficient, low-latency communication.
  • Supported across many Dgraph versions, with per-version client releases.
  • Supports connection strings that include ACL credentials, API keys, bearer tokens, and TLS options.
  • Allows multi-tenant login to specific namespaces.
  • Provides transactional operations with commit, discard, and retry guidance.
  • Handles both JSON and RDF N-Quad mutations.
  • Supports upserts and conditional mutations using @if directives.
  • Includes debugging and metadata header capabilities.
  • Includes example projects for a quickstart and TLS setup.

Related

  • Project
  • Project
  • Project
  • Project