File tree 2 files changed +12
-2
lines changed
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
68
68
name: String!
69
69
age: Float
70
70
isActive: Boolean!
71
- analytics: UserAnalytics
71
+ analytics: UserAnalytics!
72
72
periods: [UserPeriods]!
73
73
}
74
74
Original file line number Diff line number Diff line change @@ -102,15 +102,25 @@ function makeFieldsNonNullWithDefaultValues(
102
102
if ( alreadyWorked . has ( tc ) ) return ;
103
103
alreadyWorked . add ( tc ) ;
104
104
105
+ let hasFieldsWithDefaultValues = false ;
105
106
tc . getFieldNames ( ) . forEach ( ( fieldName ) => {
106
107
const fc = tc . getField ( fieldName ) ;
107
- // traverse nested Objects
108
+ // traverse nested Object types
108
109
if ( fc . type instanceof ObjectTypeComposer ) {
109
110
makeFieldsNonNullWithDefaultValues ( fc . type ) ;
111
+ if ( fc . type . getExtension ( 'hasFieldsWithDefaultValue' ) ) {
112
+ tc . makeFieldNonNull ( fieldName ) ;
113
+ }
110
114
}
115
+
111
116
const defaultValue = fc ?. extensions ?. defaultValue ;
112
117
if ( defaultValue !== null && defaultValue !== undefined ) {
118
+ hasFieldsWithDefaultValues = true ;
113
119
tc . makeFieldNonNull ( fieldName ) ;
114
120
}
115
121
} ) ;
122
+
123
+ if ( hasFieldsWithDefaultValues ) {
124
+ tc . setExtension ( 'hasFieldsWithDefaultValue' , true ) ;
125
+ }
116
126
}
You can’t perform that action at this time.
0 commit comments