Skip to content

Commit

Permalink
Patch to fix caching on datasource for mongoose models
Browse files Browse the repository at this point in the history
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
  • Loading branch information
J J Walwyn committed Oct 10, 2022
1 parent 9dc6655 commit 110493c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/__patches__/apollo-datasource-mongodb+0.5.4.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
diff --git a/node_modules/apollo-datasource-mongodb/dist/cache.js b/node_modules/apollo-datasource-mongodb/dist/cache.js
index a89c686..443ba9c 100644
--- a/node_modules/apollo-datasource-mongodb/dist/cache.js
+++ b/node_modules/apollo-datasource-mongodb/dist/cache.js
@@ -134,7 +134,7 @@ const createCachingMethods = ({
$or: filterArray
};
(0, _helpers.log)('filter: ', filter);
- const findPromise = model ? model.find(filter).exec() : collection.find(filter).toArray();
+ const findPromise = model ? model.find(filter).lean().exec() : collection.find(filter).toArray();
const results = await findPromise;
(0, _helpers.log)('results: ', results);
const orderedDocs = orderDocs(fieldsArray, results);
diff --git a/node_modules/apollo-datasource-mongodb/index.d.ts b/node_modules/apollo-datasource-mongodb/index.d.ts
index f06b4dd..6c31e07 100644
index f06b4dd..f486087 100644
--- a/node_modules/apollo-datasource-mongodb/index.d.ts
@@ -39,7 +40,7 @@ declare module 'apollo-datasource-mongodb' {
+++ b/node_modules/apollo-datasource-mongodb/index.d.ts
@@ -39,7 +39,7 @@ declare module 'apollo-datasource-mongodb' {
protected collection: Collection<TData>
protected model: Model<TData>

Expand Down

0 comments on commit 110493c

Please sign in to comment.