Skip to content

Commit 2a051be

Browse files
committed
✨ Support for sort, skip, limit in find
1 parent 04f48ae commit 2a051be

File tree

5 files changed

+218
-215
lines changed

5 files changed

+218
-215
lines changed

lib/index.d.ts

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,68 @@
1-
import { DataSource, DataSourceConfig } from "apollo-datasource";
2-
import { KeyValueCache } from "apollo-server-caching";
3-
4-
import type { Collection, Document, FindOptions } from "mongodb";
5-
declare type DataSourceOperation = "findOne" | "find" | "count";
6-
export default abstract class MongoDataSource<TSchema extends Document = Document, TContext = any> extends DataSource<TContext> {
7-
/**
8-
* MongoDB collection for the data source.
9-
*/
10-
collection: Collection<TSchema>;
11-
/**
12-
* Cache instance
13-
*/
14-
cache?: KeyValueCache<string> | undefined;
15-
/**
16-
* Request context
17-
*/
18-
context?: TContext;
19-
/**
20-
* The prefix for the cache key
21-
* @default "mongodb"
22-
*/
23-
cachePrefix: string;
24-
private pendingResults;
25-
private defaultTTL;
26-
constructor(
27-
/**
28-
* MongoDB collection for the data source.
29-
*/
30-
collection: Collection<TSchema>,
31-
/**
32-
* Cache instance
33-
*/
34-
cache?: KeyValueCache<string> | undefined,
35-
/**
36-
* Options for the DataSource
37-
*/
38-
options?: {
39-
/**
40-
* The default TTL for the cache
41-
*/
42-
defaultTTL?: number;
43-
/**
44-
* The prefix for the cache key
45-
*/
46-
cachePrefix?: string;
47-
});
48-
initialize({ context, cache }: DataSourceConfig<TContext>): void;
49-
count(query?: {}, options?: {
50-
ttl: number;
51-
}): Promise<any>;
52-
find(fields?: any, options?: {
53-
ttl: number;
54-
findOptions?: FindOptions<Document>;
55-
}): Promise<TSchema[]>;
56-
findOne(fields?: any, options?: {
57-
ttl: number;
58-
findOptions?: FindOptions;
59-
}): Promise<TSchema | null>;
60-
delete(type: DataSourceOperation, fields?: any, options?: {
61-
findOptions?: FindOptions;
62-
}): Promise<boolean | void | undefined>;
63-
private getCacheKey;
64-
private antiSpam;
65-
}
66-
export {};
1+
import { DataSource, DataSourceConfig } from "apollo-datasource";
2+
import { KeyValueCache } from "apollo-server-caching";
3+
import type { Collection, Document, FindOptions, Sort, SortDirection } from "mongodb";
4+
declare type DataSourceOperation = "findOne" | "find" | "count";
5+
export default abstract class MongoDataSource<TSchema extends Document = Document, TContext = any> extends DataSource<TContext> {
6+
/**
7+
* MongoDB collection for the data source.
8+
*/
9+
collection: Collection<TSchema>;
10+
/**
11+
* Cache instance
12+
*/
13+
cache?: KeyValueCache<string> | undefined;
14+
/**
15+
* Request context
16+
*/
17+
context?: TContext;
18+
/**
19+
* The prefix for the cache key
20+
* @default "mongodb"
21+
*/
22+
cachePrefix: string;
23+
private pendingResults;
24+
private defaultTTL;
25+
constructor(
26+
/**
27+
* MongoDB collection for the data source.
28+
*/
29+
collection: Collection<TSchema>,
30+
/**
31+
* Cache instance
32+
*/
33+
cache?: KeyValueCache<string> | undefined,
34+
/**
35+
* Options for the DataSource
36+
*/
37+
options?: {
38+
/**
39+
* The default TTL for the cache
40+
*/
41+
defaultTTL?: number;
42+
/**
43+
* The prefix for the cache key
44+
*/
45+
cachePrefix?: string;
46+
});
47+
initialize({ context, cache }: DataSourceConfig<TContext>): void;
48+
count(query?: {}, options?: {
49+
ttl: number;
50+
}): Promise<any>;
51+
find(fields?: any, options?: {
52+
ttl: number;
53+
findOptions?: FindOptions<TSchema>;
54+
}, sort?: {
55+
sort: Sort;
56+
direction?: SortDirection;
57+
}, skip?: number, limit?: number): Promise<TSchema[]>;
58+
findOne(fields?: any, options?: {
59+
ttl: number;
60+
findOptions?: FindOptions<TSchema>;
61+
}): Promise<TSchema | null>;
62+
delete(type: DataSourceOperation, fields?: any, options?: {
63+
findOptions?: FindOptions<TSchema>;
64+
}): Promise<boolean | void | undefined>;
65+
private getCacheKey;
66+
private antiSpam;
67+
}
68+
export {};

lib/index.js

Lines changed: 116 additions & 130 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)