File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ describe('issue #261 - Non-nullability for mongoose fields that have a default v
6868 name: String!
6969 age: Float
7070 isActive: Boolean!
71- analytics: UserAnalytics
71+ analytics: UserAnalytics!
7272 periods: [UserPeriods]!
7373 }
7474
Original file line number Diff line number Diff line change @@ -102,15 +102,25 @@ function makeFieldsNonNullWithDefaultValues(
102102 if ( alreadyWorked . has ( tc ) ) return ;
103103 alreadyWorked . add ( tc ) ;
104104
105+ let hasFieldsWithDefaultValues = false ;
105106 tc . getFieldNames ( ) . forEach ( ( fieldName ) => {
106107 const fc = tc . getField ( fieldName ) ;
107- // traverse nested Objects
108+ // traverse nested Object types
108109 if ( fc . type instanceof ObjectTypeComposer ) {
109110 makeFieldsNonNullWithDefaultValues ( fc . type ) ;
111+ if ( fc . type . getExtension ( 'hasFieldsWithDefaultValue' ) ) {
112+ tc . makeFieldNonNull ( fieldName ) ;
113+ }
110114 }
115+
111116 const defaultValue = fc ?. extensions ?. defaultValue ;
112117 if ( defaultValue !== null && defaultValue !== undefined ) {
118+ hasFieldsWithDefaultValues = true ;
113119 tc . makeFieldNonNull ( fieldName ) ;
114120 }
115121 } ) ;
122+
123+ if ( hasFieldsWithDefaultValues ) {
124+ tc . setExtension ( 'hasFieldsWithDefaultValue' , true ) ;
125+ }
116126}
You can’t perform that action at this time.
0 commit comments