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

meadow-connection-dgraph

v1.0.2

Published

Meadow DGraph Connection Plugin

Readme

Meadow Connection Dgraph

A Dgraph database connection provider for the Meadow ORM. Wraps dgraph-js-http as a Fable service, providing HTTP client management with optional auth token support and schema generation from Meadow table schemas.

License: MIT


Features

  • Dgraph HTTP Client -- Managed connection to Dgraph Alpha via dgraph-js-http
  • Fable Service Provider -- Registers with a Fable instance for dependency injection, logging, and configuration
  • Schema-Driven DDL -- Generates Dgraph predicate declarations and type definitions from Meadow table schemas with automatic index directives
  • Auth Token Support -- Optional Alpha auth token for secured Dgraph clusters
  • Connection Safety -- Guards against double-connect with descriptive logging
  • Direct Client Access -- Exposes the underlying Dgraph client and stub via pool and stub getters
  • Graph-Native Types -- Maps Meadow types to Dgraph scalar types with appropriate index strategies (exact, term, fulltext, int, float, hour)

Installation

npm install meadow-connection-dgraph

Quick Start

const libFable = require('fable');
const MeadowConnectionDGraph = require('meadow-connection-dgraph');

let fable = new libFable(
{
	DGraph:
	{
		Server: 'localhost',
		Port: 8080
	}
});

fable.serviceManager.addServiceType('MeadowDGraphProvider', MeadowConnectionDGraph);
fable.serviceManager.instantiateServiceProvider('MeadowDGraphProvider');

fable.MeadowDGraphProvider.connectAsync(
	(pError, pClient) =>
	{
		if (pError)
		{
			console.error('Connection failed:', pError);
			return;
		}

		// Use the Dgraph client for transactions
		let tmpTxn = pClient.newTxn();
		tmpTxn.query('{ animals(func: type(Animal)) { uid Name Age } }')
			.then((pResult) =>
			{
				console.log(pResult.data);
			});
	});

Configuration

Dgraph settings are provided through the Fable settings DGraph object or constructor options:

let fable = new libFable(
{
	DGraph:
	{
		Server: 'localhost',
		Port: 8080,
		AuthToken: ''
	}
});

Configuration Options

| Setting | Type | Default | Description | |---------|------|---------|-------------| | Server / host | String | 'localhost' | Dgraph Alpha hostname or IP | | Port / port | Number | 8080 | Dgraph Alpha HTTP port | | AuthToken / authToken | String | '' | Optional Alpha auth token | | MeadowConnectionDGraphAutoConnect | Boolean | false | Auto-connect on instantiation |

API

connectAsync(fCallback)

Open the Dgraph HTTP client connection. This is the recommended connection method.

| Parameter | Type | Description | |-----------|------|-------------| | fCallback | Function | Callback receiving (error, client) |

connect()

Synchronous connection method. Creates the client stub and client instance.

pool (getter)

Returns the underlying DgraphClient instance for direct query and mutation access.

stub (getter)

Returns the raw DgraphClientStub for low-level HTTP operations.

connected (property)

Boolean indicating whether the Dgraph client has been established.

generateCreateTableStatement(pMeadowTableSchema)

Generate Dgraph predicate declarations and a type definition from a Meadow table schema.

createTable(pMeadowTableSchema, fCallback)

Generate and apply a schema to the connected Dgraph instance via client.alter().

createTables(pMeadowSchema, fCallback)

Create all schemas defined in a Meadow schema object (iterates pMeadowSchema.Tables sequentially).

generateDropTableStatement(pTableName)

Generate a drop type descriptor for the given type name.

Predicate Type Mapping

| Meadow Type | Dgraph Type | Index Directive | |-------------|-------------|-----------------| | ID | int | @index(int) | | GUID | string | @index(exact) | | ForeignKey | int | @index(int) | | Numeric | int | @index(int) | | Decimal | float | @index(float) | | String | string | @index(exact, term) | | Text | string | @index(fulltext) | | DateTime | datetime | @index(hour) | | Boolean | int | @index(int) |

Part of the Retold Framework

Meadow Connection Dgraph is a database connector for the Meadow data access layer:

Testing

Run the test suite:

npm test

Run with coverage:

npm run coverage

Related Packages

License

MIT

Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the Retold Contributing Guide.