# nestjs-dgraph

> dgraph-js , graph database for NestJs

Latest version **0.2.3** (published 2023-01-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-dgraph
pnpm add nestjs-dgraph
yarn add nestjs-dgraph
bun add nestjs-dgraph
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2023-01-22 |
| First published | 2022-11-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 39.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | nguyen2242x@gmail.com |
| Maintainers | diepnghitinh |
| Keywords | nestjs, dgraph |

## Links

- npm: https://www.npmjs.com/package/nestjs-dgraph
- Repository: https://github.com/diepnghitinh/nestjs-dgraph
- Homepage: https://github.com/diepnghitinh/nestjs-dgraph#readme
- Issues: https://github.com/diepnghitinh/nestjs-dgraph/issues
- npm.io page: https://npm.io/package/nestjs-dgraph

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^1.2.0
- [dgraph-js-http](https://npm.io/package/dgraph-js-http.md) ^21.3.1

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2023-01-22
- 0.2.2 — 2022-11-28
- 0.2.1 — 2022-11-28
- 0.2.0 — 2022-11-25
- 0.1.6 — 2022-11-25
- 0.1.5 — 2022-11-25
- 0.1.4 — 2022-11-24
- 0.1.3 — 2022-11-24
- 0.1.2 — 2022-11-24
- 0.1.1 — 2022-11-24
- 0.1.0 — 2022-11-24

## README

## Description

Nestjs Plugin for [Dgraph community > 20.0], Support HttpClient, Grpc

## Installation

```bash
npm i --save nestjs-dgraph @grpc/grpc-js
```

## Quick Start

Import `DgraphModule` to your ApplicationModule

```typescript

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

@Module({
  imports: [
    DgraphModule.forRoot({
      stubs: [
        {
          // HTTP Client Configuration
          address: 'http://localhost:8080'
        },
        {
          // GRPC Client Configuration
          address: 'localhost:9080',
          credentials: grpc.credentials.createInsecure(),
        }
      ],
      auth_token: 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
      debug: true,
      initScript: async (client) => {
        client.newTxn().setSchema('external_id: string @index(exact) .');
      },
    })
  ],
})
export class ApplicationModule {}

```

Inject `DgraphService` to your services and access the DgraphClient

```typescript

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

  findAll() {
   const query = `{
      people(func: has(name)) {
        name
        type
      }
    }`;

    const req = await this.dgraph.call().newTxn().query(query);
    return req;
  }

  createMutation() {
    await this.dgraph
      .call()
      .newTxn()
      .mutate({
        set: [
          {
            name: 'Landlord',
            type: 'building',
          },
        ],
      });
  }

  updateMutation() {
    await this.dgraph
      .call()
      .newTxn()
      .mutate({
        set: [
          {
            uid: '0x2734',
            name: 'Landlord blue',
            type: 'building',
          },
        ],
      });
  }

  runMutationDelete() {
    await this.dgraph
      .call()
      .newTxn()
      .mutateDelete({
        uid: '0x2734',
        name: null,
        type: null,
      });
  }

}

```

---
_Source: https://npm.io/package/nestjs-dgraph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
