forked from GraphQLGuide/apollo-datasource-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
54 lines (43 loc) · 1.35 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
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> = T extends Document
? MongooseCollection
: MongoCollection<T>
export type Model<T> = T extends Document ? MongooseModel<T> : undefined
export type ModelOrCollection<T> = T extends Document
? Model<T>
: Collection<T>
export interface Fields {
[fieldName: string]: string | number | boolean | [string | number | boolean]
}
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>
}
}