Skip to content

Commit 2577a23

Browse files
author
J J Walwyn
committed
Patch to fix caching on datasource for mongoose models
Currently apollo-datasource-mongodb semi-supports mongoose. This is the second patch required to allow caching to work correctly - otherwise bjson throws circular reference errors due to how mongoose hydrates objects. By changing the mongoose integration to always return lean we can fix the conversion. Known Issue: GraphQLGuide/apollo-datasource-mongodb#74 Mongoose Lean: https://mongoosejs.com/docs/tutorials/lean.html
1 parent 4bd3ea8 commit 2577a23

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/__patches__/apollo-datasource-mongodb+0.5.4.patch

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
diff --git a/node_modules/apollo-datasource-mongodb/dist/cache.js b/node_modules/apollo-datasource-mongodb/dist/cache.js
2+
index a89c686..443ba9c 100644
3+
--- a/node_modules/apollo-datasource-mongodb/dist/cache.js
4+
+++ b/node_modules/apollo-datasource-mongodb/dist/cache.js
5+
@@ -134,7 +134,7 @@ const createCachingMethods = ({
6+
$or: filterArray
7+
};
8+
(0, _helpers.log)('filter: ', filter);
9+
- const findPromise = model ? model.find(filter).exec() : collection.find(filter).toArray();
10+
+ const findPromise = model ? model.find(filter).lean().exec() : collection.find(filter).toArray();
11+
const results = await findPromise;
12+
(0, _helpers.log)('results: ', results);
13+
const orderedDocs = orderDocs(fieldsArray, results);
114
diff --git a/node_modules/apollo-datasource-mongodb/index.d.ts b/node_modules/apollo-datasource-mongodb/index.d.ts
2-
index f06b4dd..6c31e07 100644
15+
index f06b4dd..f486087 100644
316
--- a/node_modules/apollo-datasource-mongodb/index.d.ts
4-
@@ -39,7 +40,7 @@ declare module 'apollo-datasource-mongodb' {
17+
+++ b/node_modules/apollo-datasource-mongodb/index.d.ts
18+
@@ -39,7 +39,7 @@ declare module 'apollo-datasource-mongodb' {
519
protected collection: Collection<TData>
620
protected model: Model<TData>
721

0 commit comments

Comments
 (0)