File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,20 @@ describe('Mongoose', () => {
7070 expect ( isCollectionOrModel ( undefined ) ) . toBe ( false )
7171 } )
7272
73+ test ( 'mongoose class-based components' , ( ) => {
74+ /**
75+ * @see https://github.com/GraphQLGuide/apollo-datasource-mongodb/issues/51
76+ */
77+
78+ const ClassModel = mongoose . model (
79+ class ClassModel extends mongoose . Model { } ,
80+ new Schema ( { name : 'string' } )
81+ )
82+
83+ expect ( isModel ( ClassModel ) ) . toBe ( true )
84+ expect ( isCollectionOrModel ( ClassModel ) ) . toBe ( true )
85+ } )
86+
7387 test ( 'getCollectionName' , ( ) => {
7488 expect ( getCollection ( userCollection ) . collectionName ) . toBe ( 'users' )
7589 expect ( getCollection ( UserModel ) . collectionName ) . toBe ( 'users' )
Original file line number Diff line number Diff line change 11const TYPEOF_COLLECTION = 'object'
22
3- export const isModel = x => Boolean ( x && x . name === 'model' )
3+ export const isModel = x =>
4+ Boolean (
5+ typeof x === 'function' &&
6+ x . prototype &&
7+ /**
8+ * @see https://github.com/Automattic/mongoose/blob/b4e0ae52a57b886bc7046d38332ce3b38a2f9acd/lib/model.js#L116
9+ */
10+ x . prototype . $isMongooseModelPrototype
11+ )
412
513export const isCollectionOrModel = x =>
614 Boolean ( x && ( typeof x === TYPEOF_COLLECTION || isModel ( x ) ) )
You can’t perform that action at this time.
0 commit comments