npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nest-ogm

v1.0.4

Published

Neo4j driver for NestJS

Downloads

12

Readme

nestjs module neo4j ogm

Description

Neo4j OGM module for Nest.

Installation

Using yarn

yarn add nest-ogm

Using npm

npm i nest-ogm

Quick Start

Import module

import packages

import gql from "graphql-tag";
import { Neo4jModule } from "nest-ogm";

config for connection

@Module({
  imports: [Neo4jModule.forRootAsync({
  useFactory: async () => {
    const uri = 'neo4j-uri';
    const username = 'neo4j-username';
    const password = 'neo4j-password';

    return {
      uri,
      username,
      password,
      typeDefs: [
        gql`
          " general enum example "
          enum Reaction {
            Like
            Love
            Haha
          }
        `,
      ],
      options: {
        features: {
        /**
         * https://neo4j.com/docs/graphql/current/type-definitions/directives/autogeneration/
         */
          populatedBy: {
            callbacks: {},
          },
        },
      },
    };
  }),
})
export class AppModule {}

Using

In this example we use Node with label name User, then name using to Inject User Node in UserService must same with name using in Neo4jModule.forFeature

1. Define Neo4j Node

user.node.ts

import gql from "graphql-tag";
import { Injectable, Logger } from "@nestjs/common";
import { Node } from "nest-ogm";

export const typeDefs = gql`
  type User {
    id: ID! @id
    username: String! @unique
  }
`;

/**
 * Data access layer (DAL)
 * Will be extends by Service
 * We suggest using DAL to call node method.
 * You can skip if not necessary
 */
@Injectable()
export class UserNeo4j {
  readonly logger = new Logger(UserNeo4j.name);
  private node: Node;

  constructor(node: Node) {
    this.node = node;
  }

  getNode() {
    return this.node;
  }

  async findOneById(id: string) {
    const nodes = await this.node.find({
      where: { id },
      options: { limit: 1 },
    });
    const [user] = nodes;
    return user;
  }
}

2. Inject in Service

user.service.ts

import { Injectable, Logger } from "@nestjs/common";
import { Driver, InjectDriver, InjectNode, Node } from "nest-ogm";

import { UserNeo4j } from "./user.node";

@Injectable()
export class UserService extends UserNeo4j {
  readonly logger = new Logger(UserService.name);

  /**
   * You can using method findOneById of class UserNeo4j
   */
  constructor(
    /* this inject dependent on Neo4jModule.forFeature */
    @InjectNode("User") node: Node,
    /* this inject dependent on Neo4jModule.forRootAsync */
    @InjectDriver() private readonly driver: Driver,
  ) {
    super(node);
  }

  /**
   * Get driver for cypher
   */
  getDriver() {
    return this.driver;
  }
}

3. Import in module

import { Neo4jModule } from "nest-ogm";
import { Module } from "@nestjs/common";

import { UserService } from "./user.service";
import { typeDefs } from "./user.node";

@Module({
  imports: [Neo4jModule.forFeature([{ name: "User", typeDefs }])],
  providers: [UserService],
  exports: [UserService, Neo4jModule],
})
export class UserModule {}

Support