GraphQLGuide / apollo-datasource-mongodb

Apollo data source for MongoDB
MIT License
285 stars 64 forks source link

Properly serialize/deserialize mongoose documents to/from cache #109

Open doronrk opened 2 years ago

doronrk commented 2 years ago

@lorensr How does this look to you? This is fully backwards compatible. Code expecting mongoose documents to be returned from the find... methods will not break. toObject is called only before serializing to the cache, not on the return value. When a document is deserialized from the cache, mongoose.Model.hydrate is called on the result as well because the API expects a mongoose document in this case.

Happy to address any feedback in the approach, let me know.

doronrk commented 2 years ago

@lorensr Just following up here. I can add unit tests and make changes, but wanted to first get your input on the high level approach before spending additional time.

lorensr commented 2 years ago

Hey @doronrk, sorry for the wait—code looks good, tests sound good ☺️