File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ declare module 'apollo-datasource-mongodb' {
2+ import { DataSource } from 'apollo-datasource'
3+ import { Collection as MongoCollection , ObjectId } from 'mongodb'
4+ import {
5+ Collection as MongooseCollection ,
6+ Document ,
7+ Model as MongooseModel
8+ } from 'mongoose'
9+
10+ export type Collection < T > = T extends Document
11+ ? MongooseCollection
12+ : MongoCollection < T >
13+
14+ export type Model < T > = T extends Document ? MongooseModel < T > : never
15+
16+ export type ModelOrCollection < T > = T extends Document
17+ ? Model < T >
18+ : Collection < T >
19+
20+ export interface Options {
21+ ttl : number
22+ }
23+
24+ export class MongoDataSource < TData , TContext = any > extends DataSource <
25+ TContext
26+ > {
27+ protected collection : Collection < TData >
28+ protected model : Model < TData >
29+
30+ constructor ( modelOrCollection : ModelOrCollection < TData > )
31+
32+ findOneById (
33+ id : ObjectId ,
34+ options ?: Options
35+ ) : Promise < TData | null | undefined >
36+
37+ findManyByIds (
38+ ids : ObjectId [ ] ,
39+ options ?: Options
40+ ) : Promise < ( TData | null | undefined ) [ ] >
41+
42+ deleteFromCacheById ( id : ObjectId ) : void
43+ }
44+ }
Original file line number Diff line number Diff line change 33 "version" : " 0.2.1" ,
44 "description" : " Apollo data source for MongoDB" ,
55 "main" : " dist/index.js" ,
6+ "types" : " index.d.ts" ,
67 "scripts" : {
78 "build" : " babel src -d dist --ignore **/*.test.js" ,
89 "dev" : " babel src -d dist --watch --ignore **/*.test.js" ,
2425 "@babel/cli" : " ^7.4.3" ,
2526 "@babel/core" : " ^7.4.3" ,
2627 "@babel/preset-env" : " ^7.4.3" ,
28+ "@types/mongodb" : " ^3.5.3" ,
29+ "@types/mongoose" : " ^5.7.7" ,
2730 "babel-jest" : " ^24.7.1" ,
2831 "graphql" : " ^14.2.1" ,
2932 "jest" : " ^24.7.1" ,
You can’t perform that action at this time.
0 commit comments