@@ -118,14 +118,38 @@ describe('fieldConverter', () => {
118118 } ;
119119 expect ( convertFieldToGraphQL ( mongooseField , '' , schemaComposer ) ) . toBe ( 'String' ) ;
120120 } ) ;
121+
122+ it ( 'should add GraphQLMongoID to schemaComposer' , ( ) => {
123+ schemaComposer . clear ( ) ;
124+ expect ( schemaComposer . has ( 'MongoID' ) ) . toBeFalsy ( ) ;
125+ const mongooseField = {
126+ path : 'strFieldName' ,
127+ instance : 'ObjectID' ,
128+ } ;
129+ expect ( convertFieldToGraphQL ( mongooseField , '' , schemaComposer ) ) . toBe ( 'MongoID' ) ;
130+ expect ( schemaComposer . get ( 'MongoID' ) ) . toBe ( GraphQLMongoID ) ;
131+ } ) ;
132+
133+ it ( 'should use existed GraphQLMongoID in schemaComposer' , ( ) => {
134+ schemaComposer . clear ( ) ;
135+ expect ( schemaComposer . has ( 'MongoID' ) ) . toBeFalsy ( ) ;
136+ schemaComposer . set ( 'MongoID' , ( 'MockGraphQLType' : any ) ) ;
137+ const mongooseField = {
138+ path : 'strFieldName' ,
139+ instance : 'ObjectID' ,
140+ } ;
141+ expect ( convertFieldToGraphQL ( mongooseField , '' , schemaComposer ) ) . toBe ( 'MongoID' ) ;
142+ expect ( schemaComposer . get ( 'MongoID' ) ) . toBe ( 'MockGraphQLType' ) ;
143+ schemaComposer . delete ( 'MongoID' ) ;
144+ } ) ;
121145 } ) ;
122146
123147 describe ( 'scalarToGraphQL()' , ( ) => {
124148 it ( 'should properly convert mongoose scalar type to default graphQL types' , ( ) => {
125149 expect ( scalarToGraphQL ( { instance : 'String' } ) ) . toBe ( 'String' ) ;
126150 expect ( scalarToGraphQL ( { instance : 'Number' } ) ) . toBe ( 'Float' ) ;
127151 expect ( scalarToGraphQL ( { instance : 'Boolean' } ) ) . toBe ( 'Boolean' ) ;
128- expect ( scalarToGraphQL ( { instance : 'ObjectID' } ) ) . toBe ( GraphQLMongoID ) ;
152+ expect ( scalarToGraphQL ( { instance : 'ObjectID' } ) ) . toBe ( 'MongoID' ) ;
129153 } ) ;
130154
131155 it ( 'should properly convert mongoose scalar type to scalar graphql-compose types' , ( ) => {
@@ -196,7 +220,7 @@ describe('fieldConverter', () => {
196220
197221 describe ( 'referenceToGraphQL()' , ( ) => {
198222 it ( 'should return type of field' , ( ) => {
199- expect ( referenceToGraphQL ( fields . user ) ) . toBe ( GraphQLMongoID ) ;
223+ expect ( referenceToGraphQL ( fields . user ) ) . toBe ( 'MongoID' ) ;
200224 } ) ;
201225 } ) ;
202226} ) ;
0 commit comments