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 3
3
"version" : " 0.2.1" ,
4
4
"description" : " Apollo data source for MongoDB" ,
5
5
"main" : " dist/index.js" ,
6
+ "types" : " index.d.ts" ,
6
7
"scripts" : {
7
8
"build" : " babel src -d dist --ignore **/*.test.js" ,
8
9
"dev" : " babel src -d dist --watch --ignore **/*.test.js" ,
24
25
"@babel/cli" : " ^7.4.3" ,
25
26
"@babel/core" : " ^7.4.3" ,
26
27
"@babel/preset-env" : " ^7.4.3" ,
28
+ "@types/mongodb" : " ^3.5.3" ,
29
+ "@types/mongoose" : " ^5.7.7" ,
27
30
"babel-jest" : " ^24.7.1" ,
28
31
"graphql" : " ^14.2.1" ,
29
32
"jest" : " ^24.7.1" ,
You can’t perform that action at this time.
0 commit comments