🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

apollo-mongodb-datasource

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-mongodb-datasource

An Apollo GraphQL Datasource using MongoDB.

latest
Source
npmnpm
Version
1.3.3
Version published
Weekly downloads
3
-57.14%
Maintainers
2
Weekly downloads
 
Created
Source

MongoDataSource

An Apollo GraphQL Datasource using MongoDB.

Why

While there already is a somewhat good MongoDB DataSource package available (apollo-datasource-mongodb), it still lacks some features / functions that we needed in our projects, while it doesn't yet support the main feature of the existing package (Batching), it fixes other small issues like the prevention of spamming MongoDB with requests when there's already a query running for it.

This DataSource is currently in use by PreMiD/API at a large scale.

Installation

# NPM
npm i apollo-mongodb-datasource

# YARN
yarn add apollo-mongodb-datasource

Usage

TypeScript

index.ts

import { MongoClient } from 'mongodb'

import Users from './dataSources/Users'

const client = new MongoClient('mongodb://localhost:27017/test');
client.connect()

const server = new ApolloServer({
  typeDefs,
  resolvers,
  dataSources: () => ({
    users: new Users(client.db().collection('users'))
  })
})

Users.ts

import MongoDataSource from 'apollo-mongodb-datasource'

export default class Users extends MongoDataSource {
  getUser(userId: string) {
    return this.findOne({userId})
  }
}

FAQs

Package last updated on 27 Mar 2022

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