Skip to content

Commit e272577

Browse files
committed
🐛 Use Filter type
1 parent 2a051be commit e272577

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apollo-mongodb-datasource",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "An Apollo GraphQL Datasource using MongoDB.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { KeyValueCache } from "apollo-server-caching";
44
import type {
55
Collection,
66
Document,
7+
Filter,
78
FindOptions,
89
Sort,
910
SortDirection
@@ -66,7 +67,7 @@ export default abstract class MongoDataSource<
6667
this.context = context;
6768
}
6869

69-
async count(query: {} = {}, options = { ttl: this.defaultTTL }) {
70+
async count(query: Filter<TSchema> = {}, options = { ttl: this.defaultTTL }) {
7071
const cacheKey = this.getCacheKey("count", query),
7172
cacheDoc = await this.cache?.get(cacheKey);
7273
if (cacheDoc) return JSON.parse(cacheDoc);
@@ -82,7 +83,7 @@ export default abstract class MongoDataSource<
8283
}
8384

8485
async find(
85-
fields: any = {},
86+
fields: Filter<TSchema> = {},
8687
options: { ttl: number; findOptions?: FindOptions<TSchema> } = {
8788
ttl: this.defaultTTL
8889
},
@@ -117,7 +118,7 @@ export default abstract class MongoDataSource<
117118
}
118119

119120
async findOne(
120-
fields: any = {},
121+
fields: Filter<TSchema> = {},
121122
options: { ttl: number; findOptions?: FindOptions<TSchema> } = {
122123
ttl: this.defaultTTL
123124
}
@@ -139,15 +140,15 @@ export default abstract class MongoDataSource<
139140

140141
async delete(
141142
type: DataSourceOperation,
142-
fields: any = {},
143+
fields: Filter<TSchema> = {},
143144
options: { findOptions?: FindOptions<TSchema> } = {}
144145
) {
145146
return await this.cache?.delete(this.getCacheKey(type, fields, options));
146147
}
147148

148149
private getCacheKey(
149150
type: DataSourceOperation,
150-
fields: any,
151+
fields: Filter<TSchema>,
151152
options: { findOptions?: FindOptions<TSchema> } = {},
152153
sort?: { sort: Sort; direction?: SortDirection },
153154
skip?: number,

0 commit comments

Comments
 (0)