Socket
Socket
Sign inDemoInstall

apollo-mongodb-datasource

Package Overview
Dependencies
34
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    apollo-mongodb-datasource

An Apollo GraphQL Datasource using MongoDB.


Version published
Maintainers
2
Install size
14.4 MB
Created

Readme

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

Last updated on 27 Mar 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc