leesiongchan / nestjs-dgraph

dgraph-js module for Nest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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);
  }
}

Example

See a simple example.

Further Reading

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

About

dgraph-js module for Nest

License:MIT License


Languages

Language:TypeScript 94.8%Language:JavaScript 5.2%