@valsamonte/nestjs-dgraph
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

Description

dgraph-js module for Nest.

Installation

npm i --save @valsamonte/nestjs-dgraph dgraph-js grpc

Quick Start

Import DgraphModule to your ApplicationModule

import { Module } from '@nestjs/common';
import { DgraphModule } from '@valsamonte/nestjs-dgraph';
import * as grpc from 'grpc';

@Module({
  imports: [
    DgraphModule.forRoot({
      stubs: [
        {
          address: 'localhost:9080',
          credentials: grpc.credentials.createInsecure()
        }
      ]
      debug: true
    })
  ],
})
export class ApplicationModule {}

Inject DgraphService to your services and access the DgraphClient

@Injectable()
export class SomeService {
  constructor(dgraph: DgraphService) {}

  alterSchema() {
    const schema = "name: string @index(exact) .";
    const op = new dgraph.Operation();
    op.setSchema(schema);
    await this.dgraph.client.alter(op);
  }

  dropAll() {
    const op = new dgraph.Operation();
    op.setDropAll(true);
    await this.dgraph.client.alter(op);
  }
}

Further Reading

Refer to dgraph-js official docs for more dgraph usage.

Readme

Keywords

Package Sidebar

Install

npm i @valsamonte/nestjs-dgraph

Weekly Downloads

1

Version

0.1.6

License

MIT

Unpacked Size

12.3 kB

Total Files

19

Last publish

Collaborators

  • valsamonte