forked from GraphQLGuide/apollo-datasource-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
61 lines (50 loc) · 1.44 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
declare module 'apollo-datasource-mongodb' {
import { DataSource } from 'apollo-datasource'
import { Collection as MongoCollection, ObjectId } from 'mongodb'
import {
Collection as MongooseCollection,
Document,
Model as MongooseModel,
} from 'mongoose'
export type Collection<T, U = MongoCollection<T>> = T extends Document
? MongooseCollection
: U
export type Model<T, U = MongooseModel<T>> = T extends Document
? U
: undefined
export type ModelOrCollection<T, U = Model<T>> = T extends Document
? U
: Collection<T>
export interface Fields {
[fieldName: string]:
| string
| number
| boolean
| ObjectId
| (string | number | boolean | ObjectId)[]
}
export interface Options {
ttl: number
}
export class MongoDataSource<TData, TContext = any> extends DataSource<
TContext
> {
protected context: TContext
protected collection: Collection<TData>
protected model: Model<TData>
constructor(modelOrCollection: ModelOrCollection<TData>)
findOneById(
id: ObjectId | string,
options?: Options
): Promise<TData | null | undefined>
findManyByIds(
ids: (ObjectId | string)[],
options?: Options
): Promise<(TData | null | undefined)[]>
findByFields(
fields: Fields,
options?: Options
): Promise<(TData | null | undefined)[]>
deleteFromCacheById(id: ObjectId | string): Promise<void>
}
}