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', () => {
70
70
expect ( isCollectionOrModel ( undefined ) ) . toBe ( false )
71
71
} )
72
72
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
+
73
87
test ( 'getCollectionName' , ( ) => {
74
88
expect ( getCollection ( userCollection ) . collectionName ) . toBe ( 'users' )
75
89
expect ( getCollection ( UserModel ) . collectionName ) . toBe ( 'users' )
Original file line number Diff line number Diff line change 1
1
const TYPEOF_COLLECTION = 'object'
2
2
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
+ )
4
12
5
13
export const isCollectionOrModel = x =>
6
14
Boolean ( x && ( typeof x === TYPEOF_COLLECTION || isModel ( x ) ) )
You can’t perform that action at this time.
0 commit comments