You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add findByFields method
* Prettify, fix filters mixing, and improve caching
* Remove bad test
While the key didn't get cached in the new InMemoryLRUCache that's passed to createCachingMethods, it did get cached by the DataLoader's memoization cache since .load() is called twice with the same key. See https://github.com/graphql/dataloader#caching
* Add findByFields tests
* Add findByFields to ts module
* Add findByFields to README
* Ensure non-array field value cache keys are saved as arrays
* Add more cache testing for findByFields
* Clean up code
* Sort fields before caching or calling loader
Co-authored-by: Aditya Thakral <[email protected]>
Co-authored-by: Aditya Thakral <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+38-1
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,11 @@ Apollo [data source](https://www.apollographql.com/docs/apollo-server/features/d
6
6
npm i apollo-datasource-mongodb
7
7
```
8
8
9
-
This package uses [DataLoader](https://github.com/graphql/dataloader) for batching and per-request memoization caching. It also optionally (if you provide a `ttl`) does shared application-level caching (using either the default Apollo `InMemoryLRUCache` or the [cache you provide to ApolloServer()](https://www.apollographql.com/docs/apollo-server/features/data-sources#using-memcachedredis-as-a-cache-storage-backend)). It does this only for these two methods:
9
+
This package uses [DataLoader](https://github.com/graphql/dataloader) for batching and per-request memoization caching. It also optionally (if you provide a `ttl`) does shared application-level caching (using either the default Apollo `InMemoryLRUCache` or the [cache you provide to ApolloServer()](https://www.apollographql.com/docs/apollo-server/features/data-sources#using-memcachedredis-as-a-cache-storage-backend)). It does this for the following methods:
10
10
11
11
-[`findOneById(id, options)`](#findonebyid)
12
12
-[`findManyByIds(ids, options)`](#findmanybyids)
13
+
-[`findByFields(fields, options)`](#findbyfields)
13
14
14
15
15
16
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
@@ -24,6 +25,8 @@ This package uses [DataLoader](https://github.com/graphql/dataloader) for batchi
24
25
-[API](#api)
25
26
-[findOneById](#findonebyid)
26
27
-[findManyByIds](#findmanybyids)
28
+
-[findByFields](#findbyfields)
29
+
-[Examples:](#examples)
27
30
-[deleteFromCacheById](#deletefromcachebyid)
28
31
29
32
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -183,6 +186,7 @@ interface UserDocument {
183
186
username:string
184
187
password:string
185
188
email:string
189
+
interests: [string]
186
190
}
187
191
188
192
// This is optional
@@ -236,6 +240,39 @@ Resolves to the found document. Uses DataLoader to load `id`. DataLoader uses `c
236
240
237
241
Calls [`findOneById()`](#findonebyid) for each id. Resolves to an array of documents.
238
242
243
+
### findByFields
244
+
245
+
`this.findByFields(fields, { ttl })`
246
+
247
+
Resolves to an array of documents matching the passed fields.
248
+
249
+
fields has type `{ [fieldName: string]: string | number | boolean | [string | number | boolean] }`.
0 commit comments