1.0.0 • Published 7 months ago

nest-tigergraph v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

@nestjs/tigergraph

A NestJS module for TigerGraph integration.

Installation

npm install @nestjs/tigergraph

Usage

// Static configuration
import { Module } from '@nestjs/common';
import { TigerGraphModule } from '@nestjs/tigergraph';

@Module({
  imports: [
    TigerGraphModule.register({
      host: 'localhost',
      port: 14240,
      graphName: 'myGraph',
      userName: 'user',
      password: 'pass',
    }),
  ],
})
export class AppModule {}

// Async configuration
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TigerGraphModule } from '@nestjs/tigergraph';

@Module({
  imports: [
    ConfigModule.forRoot(),
    TigerGraphModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        host: configService.get('TIGERGRAPH_HOST'),
        port: configService.get('TIGERGRAPH_PORT'),
        graphName: configService.get('TIGERGRAPH_GRAPH'),
        userName: configService.get('TIGERGRAPH_USER'),
        password: configService.get('TIGERGRAPH_PASSWORD'),
      }),
      inject: [ConfigService],
    }),
  ],
})
export class AppModule {}

// Using the service
import { Injectable } from '@nestjs/common';
import { TigerGraphService } from '@nestjs/tigergraph';

@Injectable()
export class YourService {
  constructor(private readonly tigerGraphService: TigerGraphService) {}

  async getData() {
    const result = await this.tigerGraphService.query('yourQuery', {
      param1: 'value1',
    });
    return result;
  }
}

API Reference

TigerGraphModule

  • register(options: ITigerGraphOptions): Static configuration
  • forRootAsync(options: ITigerGraphAsyncOptions): Async configuration

TigerGraphService

  • connect(): Establish connection to TigerGraph
  • query<T>(queryName: string, params?: Record<string, any>): Promise<T>: Execute a query
1.0.0

7 months ago