@@ -12,9 +12,11 @@ import type { GraphQLFieldConfigMap } from 'graphql-compose/lib/graphql';
1212import type {
1313 ComposePartialFieldConfigAsObject ,
1414 RelationOpts ,
15+ ComposeFieldConfig ,
16+ GetRecordIdFn ,
1517} from 'graphql-compose/lib/TypeComposer' ;
1618import { Model } from 'mongoose' ;
17- import { type TypeConverterOpts , composeWithMongoose } from '../composeWithMongoose' ;
19+ import { composeWithMongoose , type TypeConverterOpts } from '../composeWithMongoose' ;
1820import { composeChildTC } from './composeChildTC' ;
1921import { mergeCustomizationOptions } from './merge-customization-options' ;
2022import { prepareBaseResolvers } from './prepare-resolvers/prepareBaseResolvers' ;
@@ -164,18 +166,68 @@ export class DiscriminatorTypeComposer extends TypeComposer {
164166 return ! ! this . childTCs . find ( ch => ch . getTypeName ( ) === DName ) ;
165167 }
166168
167- // add fields only to DInterface, baseTC, childTC
168- addDFields ( newDFields : ComposeFieldConfigMap < any , any > ) : this {
169- super . addFields ( newDFields ) ;
169+ setFields ( fields : ComposeFieldConfigMap < any , any > ) : this {
170+ super . setFields ( fields ) ;
170171
171172 for ( const childTC of this . childTCs ) {
172- childTC . addFields ( newDFields ) ;
173+ childTC . setFields ( fields ) ;
173174 }
174175
175176 return this ;
176177 }
177178
178- extendDField (
179+ setField ( fieldName : string , fieldConfig : ComposeFieldConfig < any , any > ) : this {
180+ super . setField ( fieldName , fieldConfig ) ;
181+
182+ for ( const childTC of this . childTCs ) {
183+ childTC . setField ( fieldName , fieldConfig ) ;
184+ }
185+
186+ return this ;
187+ }
188+
189+ // discriminators must have all interface fields
190+ addFields ( newFields : ComposeFieldConfigMap < any , any > ) : this {
191+ super . addFields ( newFields ) ;
192+
193+ for ( const childTC of this . childTCs ) {
194+ childTC . addFields ( newFields ) ;
195+ }
196+
197+ return this ;
198+ }
199+
200+ addNestedFields ( newFields : ComposeFieldConfigMap < any , any > ) : this {
201+ super . addNestedFields ( newFields ) ;
202+
203+ for ( const childTC of this . childTCs ) {
204+ childTC . addNestedFields ( newFields ) ;
205+ }
206+
207+ return this ;
208+ }
209+
210+ removeField ( fieldNameOrArray : string | Array < string > ) : this {
211+ super . removeField ( fieldNameOrArray ) ;
212+
213+ for ( const childTC of this . childTCs ) {
214+ childTC . removeField ( fieldNameOrArray ) ;
215+ }
216+
217+ return this ;
218+ }
219+
220+ removeOtherFields ( fieldNameOrArray : string | Array < string > ) : this {
221+ super . removeOtherFields ( fieldNameOrArray ) ;
222+
223+ for ( const childTC of this . childTCs ) {
224+ childTC . removeOtherFields ( fieldNameOrArray ) ;
225+ }
226+
227+ return this ;
228+ }
229+
230+ extendField (
179231 fieldName : string ,
180232 partialFieldConfig : ComposePartialFieldConfigAsObject < any , any >
181233 ) : this {
@@ -188,13 +240,52 @@ export class DiscriminatorTypeComposer extends TypeComposer {
188240 return this ;
189241 }
190242
243+ reorderFields ( names : string [ ] ) : this {
244+ super . reorderFields ( names ) ;
245+
246+ for ( const childTC of this . childTCs ) {
247+ childTC . reorderFields ( names ) ;
248+ }
249+
250+ return this ;
251+ }
252+
253+ makeFieldNonNull ( fieldNameOrArray : string | Array < string > ) : this {
254+ super . makeFieldNonNull ( fieldNameOrArray ) ;
255+
256+ for ( const childTC of this . childTCs ) {
257+ childTC . makeFieldNonNull ( fieldNameOrArray ) ;
258+ }
259+
260+ return this ;
261+ }
262+
263+ makeFieldNullable ( fieldNameOrArray : string | Array < string > ) : this {
264+ super . makeFieldNullable ( fieldNameOrArray ) ;
265+
266+ for ( const childTC of this . childTCs ) {
267+ childTC . makeFieldNullable ( fieldNameOrArray ) ;
268+ }
269+
270+ return this ;
271+ }
272+
273+ deprecateFields ( fields : { [ fieldName : string ] : string } | string [ ] | string ) : this {
274+ super . deprecateFields ( fields ) ;
275+
276+ for ( const childTC of this . childTCs ) {
277+ childTC . deprecateFields ( fields ) ;
278+ }
279+
280+ return this ;
281+ }
282+
191283 // relations with args are a bit hard to manage as interfaces i believe as of now do not
192284 // support field args. Well if one wants to have use args, you setType for resolver as this
193285 // this = this DiscriminantTypeComposer
194286 // NOTE, those relations will be propagated to the childTypeComposers and you can use normally.
195- // FixMe: Note, You must use this function after creating all discriminators
196- addDRelation ( fieldName : string , relationOpts : RelationOpts < any , any > ) : this {
197- this . addRelation ( fieldName , relationOpts ) ;
287+ addRelation ( fieldName : string , relationOpts : RelationOpts < any , any > ) : this {
288+ super . addRelation ( fieldName , relationOpts ) ;
198289
199290 for ( const childTC of this . childTCs ) {
200291 childTC . addRelation ( fieldName , relationOpts ) ;
@@ -203,6 +294,16 @@ export class DiscriminatorTypeComposer extends TypeComposer {
203294 return this ;
204295 }
205296
297+ setRecordIdFn ( fn : GetRecordIdFn < any , any > ) : this {
298+ super . setRecordIdFn ( fn ) ;
299+
300+ for ( const childTC of this . childTCs ) {
301+ childTC . setRecordIdFn ( fn ) ;
302+ }
303+
304+ return this ;
305+ }
306+
206307 /* eslint no-use-before-define: 0 */
207308 discriminator ( childModel : Model , opts ? : TypeConverterOpts ) : TypeComposer {
208309 const customizationOpts = mergeCustomizationOptions (
0 commit comments