File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed
Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,18 @@ const UserSchema = new Schema(
130130 ] ,
131131 } ,
132132
133+ statusCode : {
134+ type : Number ,
135+ enum : Object . values ( {
136+ ACTIVE : 1 ,
137+ INACTIVE : 2 ,
138+ } ) ,
139+ } ,
140+
141+ numTest : {
142+ type : Number ,
143+ } ,
144+
133145 // createdAt, created via option `timestamp: true` (see bottom)
134146 // updatedAt, created via option `timestamp: true` (see bottom)
135147 } ,
Original file line number Diff line number Diff line change @@ -116,6 +116,14 @@ describe('fieldConverter', () => {
116116 it ( 'should derive MIXED mongoose type' , ( ) => {
117117 expect ( deriveComplexType ( fields . someDynamic ) ) . toBe ( ComplexTypes . MIXED ) ;
118118 } ) ;
119+
120+ it ( 'should derive Number mongoose type' , ( ) => {
121+ expect ( deriveComplexType ( fields . numTest ) ) . toBe ( ComplexTypes . SCALAR ) ;
122+ } ) ;
123+
124+ it ( 'should derive Enum Number mongoose type' , ( ) => {
125+ expect ( deriveComplexType ( fields . statusCode ) ) . toBe ( ComplexTypes . SCALAR ) ;
126+ } ) ;
119127 } ) ;
120128
121129 describe ( 'convertFieldToGraphQL()' , ( ) => {
@@ -163,6 +171,17 @@ describe('fieldConverter', () => {
163171 expect ( schemaComposer . has ( 'BSONDecimal' ) ) . toBeTruthy ( ) ;
164172 expect ( schemaComposer . get ( 'BSONDecimal' ) . getType ( ) ) . toBe ( GraphQLBSONDecimal ) ;
165173 } ) ;
174+
175+ it ( 'should use Scalar[float] for Enum Numbers' , ( ) => {
176+ schemaComposer . clear ( ) ;
177+ expect ( schemaComposer . has ( 'statusCode' ) ) . toBeFalsy ( ) ;
178+ const mongooseField = {
179+ path : 'statusCode' ,
180+ instance : 'Number' ,
181+ enumValues : [ 1 , 2 , 3 ] ,
182+ } ;
183+ expect ( convertFieldToGraphQL ( mongooseField , '' , schemaComposer ) ) . toBe ( 'Float' ) ;
184+ } ) ;
166185 } ) ;
167186
168187 describe ( 'scalarToGraphQL()' , ( ) => {
Original file line number Diff line number Diff line change @@ -294,6 +294,8 @@ export function deriveComplexType(field: MongooseFieldT): ComplexTypes {
294294 return ComplexTypes . REFERENCE ;
295295 } else if ( fieldType === 'Decimal128' ) {
296296 return ComplexTypes . DECIMAL ;
297+ } else if ( fieldType === 'Number' ) {
298+ return ComplexTypes . SCALAR ;
297299 }
298300
299301 const enums = _getFieldEnums ( field ) ;
@@ -394,8 +396,6 @@ export function enumToGraphQL(
394396 key = 'NULL' ;
395397 } else if ( value === '' ) {
396398 key = 'EMPTY_STRING' ;
397- } else if ( typeof value === 'number' ) {
398- key = value ;
399399 } else {
400400 key = value
401401 ?. toString ( )
You can’t perform that action at this time.
0 commit comments