1.3.3 • Published 2 years ago

apollo-mongodb-datasource v1.3.3

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
2 years ago

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})
  }
}
1.2.0

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

3 years ago

1.0.0

3 years ago