🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more
Socket
Book a DemoInstallSign in
Socket

@envelop/dataloader

Package Overview
Dependencies
Maintainers
1
Versions
1400
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@envelop/dataloader

This plugin helps you to create a new [DataLoader](https://github.com/graphql/dataloader) instance every time your context is being built. The created instance is injected into the `context` with the name you wish to use.

Source
npmnpm
Version
7.1.3-alpha-20250306144220-1ff4a8bf12b31f7c947de7059536e39828d47ada
Version published
Weekly downloads
5.4K
-50.87%
Maintainers
1
Weekly downloads
 
Created
Source

@envelop/dataloader

This plugin helps you to create a new DataLoader instance every time your context is being built. The created instance is injected into the context with the name you wish to use.

Getting Started

yarn add dataloader @envelop/dataloader

Usage Example

import DataLoader from 'dataloader'
import { execute, parse, specifiedRules, subscribe, validate } from 'graphql'
import { envelop, useEngine } from '@envelop/core'
import { useDataLoader } from '@envelop/dataloader'

const getEnveloped = envelop({
  plugins: [
    useEngine({ parse, validate, specifiedRules, execute, subscribe }),
    // ... other plugins ...
    useDataLoader('users', context => new DataLoader(keys => myBatchGetUsers(keys)))
  ]
})

Then, when you need to use it in your resolvers, just take it from the context:

export const resolvers = {
  Query: {
    user: (root, args, context, info) => {
      return context.users.load(args.id)
    }
  }
}

Notes

There are several ways to create and use DataLoader, please refer to: https://github.com/graphql/dataloader#caching-per-request for more details.

FAQs

Package last updated on 06 Mar 2025

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