Socket
Book a DemoInstallSign in
Socket

@jenyus-org/nestjs-graphql-utils

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jenyus-org/nestjs-graphql-utils

NestJS utilities and decorators built around @jenyus-org/graphql-utils.

latest
Source
npmnpm
Version
1.6.4
Version published
Maintainers
2
Created
Source

nestjs-graphql-utils

License: MIT NPM Release NPM Downloads NPM Type Definitions

@jenyus-org/nestjs-graphql-utils is a collection of utilities and decorators built on top of @jenyus-org/graphql-utils to encourage the stateless nature of NestJS GraphQL resolvers and simplify the usage of helpers.

Documentation

The full documentation with live code sandboxes can be found here.

Installation

@jenyus-org/nestjs-graphql-utils can be installed from NPM by running one of the following commands:

NPM:

npm i --save @jenyus-org/nestjs-graphql-utils

Yarn:

yarn add @jenyus-org/nestjs-graphql-utils

This will install @jenyus-org/nestjs-graphql-utils and all its dependencies.

Getting Started

Typically, you will want to use the NestJS GraphQL-Utils package and its decorators to optimize your SQL SELECT and JOIN statements. You can use the @Selections() decorator and wildcards to get the precise fields and relations to populate:

import { Selections } from "@jenyus-org/nestjs-graphql-utils";
import { Parent, Query, ResolveField, Resolver } from "@nestjs/graphql";
import { UserObject } from "../users/dto/user.object";
import { UsersService } from "../users/users.service";
import { PostObject } from "./dto/post.object";
import { Post } from "./entities/post.entity";
import { PostsService } from "./posts.service";

@Resolver(() => PostObject)
class PostsResolver {
  constructor(
    private postsService: PostsService,
    private usersService: UsersService
  ) {}

  @Query(() => [PostObject])
  posts(
    @Selections("posts", ["**.**"])
    relations: string[],
    @Selections("posts", ["*."]) fields: string[]
  ) {
    return await this.postsService.findAll({ relations, fields });
  }

  @ResolveField(() => UserObject)
  async author(@Parent() post: Post) {
    if (post.author) {
      return post.author;
    }
    return await this.usersService.findOne({ postId: post.id });
  }
}

Keywords

typescript

FAQs

Package last updated on 24 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts