Skip to content

Commit 04f48ae

Browse files
author
=
committed
2 parents 5a0844b + ed8de77 commit 04f48ae

File tree

4 files changed

+141
-109
lines changed

4 files changed

+141
-109
lines changed

lib/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DataSource, DataSourceConfig } from "apollo-datasource";
22
import { KeyValueCache } from "apollo-server-caching";
3+
34
import type { Collection, Document, FindOptions } from "mongodb";
45
declare type DataSourceOperation = "findOne" | "find" | "count";
56
export default abstract class MongoDataSource<TSchema extends Document = Document, TContext = any> extends DataSource<TContext> {
@@ -26,11 +27,11 @@ export default abstract class MongoDataSource<TSchema extends Document = Documen
2627
/**
2728
* MongoDB collection for the data source.
2829
*/
29-
collection: Collection<TSchema>,
30+
collection: Collection<TSchema>,
3031
/**
3132
* Cache instance
3233
*/
33-
cache?: KeyValueCache<string> | undefined,
34+
cache?: KeyValueCache<string> | undefined,
3435
/**
3536
* Options for the DataSource
3637
*/

lib/index.js

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

lib/index.js.map

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default abstract class MongoDataSource<
7777

7878
async find(
7979
fields: any = {},
80-
options: { ttl: number; findOptions?: FindOptions<Document> } = {
80+
options: { ttl: number; findOptions?: FindOptions<TSchema> } = {
8181
ttl: this.defaultTTL
8282
}
8383
): Promise<TSchema[]> {
@@ -100,7 +100,7 @@ export default abstract class MongoDataSource<
100100

101101
async findOne(
102102
fields: any = {},
103-
options: { ttl: number; findOptions?: FindOptions } = {
103+
options: { ttl: number; findOptions?: FindOptions<TSchema> } = {
104104
ttl: this.defaultTTL
105105
}
106106
): Promise<TSchema | null> {
@@ -122,15 +122,15 @@ export default abstract class MongoDataSource<
122122
async delete(
123123
type: DataSourceOperation,
124124
fields: any = {},
125-
options: { findOptions?: FindOptions } = {}
125+
options: { findOptions?: FindOptions<TSchema> } = {}
126126
) {
127127
return await this.cache?.delete(this.getCacheKey(type, fields, options));
128128
}
129129

130130
private getCacheKey(
131131
type: DataSourceOperation,
132132
fields: any,
133-
options: { findOptions?: FindOptions } = {}
133+
options: { findOptions?: FindOptions<TSchema> } = {}
134134
) {
135135
return (
136136
this.cachePrefix +

0 commit comments

Comments
 (0)