-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from 9at8/types
Add TypeScript declarations
- Loading branch information
Showing
3 changed files
with
1,694 additions
and
1,580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 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, | ||
options?: Options | ||
): Promise<TData | null | undefined> | ||
|
||
findManyByIds( | ||
ids: ObjectId[], | ||
options?: Options | ||
): Promise<(TData | null | undefined)[]> | ||
|
||
deleteFromCacheById(id: ObjectId): void | ||
} | ||
} |
Oops, something went wrong.