0.1.6 • Published 6 years ago

@valsamonte/nestjs-dgraph v0.1.6

Weekly downloads
9
License
MIT
Repository
github
Last release
6 years ago

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.

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago