GraphQLGuide / apollo-datasource-mongodb

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

Replace dynamic collection property name #4

Closed sbrichardson closed 5 years ago

sbrichardson commented 5 years ago

At first glance, it seems you could accidentally overwrite a class method or other info if a collection name matches an existing class property? Probably rare or I could also be wrong.

For example (haven’t tested) if you have a collection called “initialize”, “collectionName”, or “context” etc.

The constructor code referring to:

this[this.collectionName] = collection[this.collectionName]

If so, maybe storing it to a collection property etc?

lorensr commented 5 years ago

Hah, yes that would be a problem. I think rare as well 😊. Could blacklist initialize etc and do a runtime check in the constructor. I wonder which of these APIs people would like more:

// current
this.users.findOne()

// proposed
this.collection.findOne()
lorensr commented 5 years ago

Replaced with this.collection (or this.model for mongoose): https://github.com/GraphQLGuide/apollo-datasource-mongodb/releases/tag/0.2.0