New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tracworx/nestjs-dataloader

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tracworx/nestjs-dataloader

Quick and easy GraphQL dataloaders for NestJS

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

GraphQL Dataloaders for NestJS

NPM Version Package License Libraries.io dependency status for latest release NPM Downloads Lint Code Base Node.js CI Node.js Package Maintainability Test Coverage Twitter

Description

Quick and easy GraphQL dataloaders for NestJS.

Installation

$ npm install @tracworx/nestjs-dataloader

Usage

Import the DataloaderModule in your root module.

import { Module } from '@nestjs/common';
import { DataloaderModule } from '@tracworx/nestjs-dataloader';
import { ItemResolver } from './item.resolver';
import { ItemLoader } from './item.loader';

@Module({
  imports: [DataloaderModule],
  providers: [ItemResolver, ItemLoader],
})
export class AppModule {}

Decorate dataloader factory classes with @DataloaderProvider() to automatically provide them to the GraphQL context object for each request.

import DataLoader from 'dataloader';
import { DataloaderProvider } from '@tracworx/nestjs-dataloader';

@DataloaderProvider()
class ItemLoader {
  createDataloader(ctx: GqlExecutionContext) {
    // Fetch request-scoped context data if needed
    const user = ctx.getContext().req.user;
    // Replace this with your actual dataloader implementation
    return new DataLoader<string, Item>(async (ids) => getItemsWithIds(user, ids));
  }
}

Use @Loader(...) to inject a dataloader instance into your resolver methods.

import DataLoader from 'dataloader';
import { Loader } from '@tracworx/nestjs-dataloader';
import { ItemLoader } from './item.loader';

@Resolver()
class ItemResolver {
  @Query(() => Item, { name: 'item' })
  getItem(@Args('id') id: string, @Loader(ItemLoader) itemLoader) {
    return itemLoader.load(id);
  }
}

And that's it. Happy coding!

Development

# build
$ npm run build

# format with prettier
$ npm run format

# lint with eslint
$ npm run lint

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Stay in touch

License

@tracworx/nestjs-dataloader is MIT licensed.

Keywords

FAQs

Package last updated on 23 Feb 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc