import { ObjectTypeComposer } from 'graphql-compose' ; import type { DiscriminatorTypeComposer , ComposeWithMongooseDiscriminatorsOpts , } from './DiscriminatorTypeComposer' ; import { prepareChildResolvers } from './prepareChildResolvers' ; import { reorderFields } from './utils/reorderFields' ; function copyBaseTcRelationsToChildTc ( baseDTC , childTC ) { const relations = baseDTC . getRelations ( ) ; const childRelations = childTC . getRelations ( ) ; Object . keys ( relations ) . forEach ( ( name ) => { if ( childRelations [ name ] ) { return ; } childTC . addRelation ( name , relations [ name ] ) ; } ) ; return childTC ; } function copyBaseTCFieldsToChildTC ( baseDTC , childTC ) { const baseFields = baseDTC . getFieldNames ( ) ; const childFields = childTC . getFieldNames ( ) ; for ( const field of baseFields ) { const isFieldExists = childFields . find ( ( fld ) => fld === field ) ; if ( isFieldExists ) { childTC . extendField ( field , { type : baseDTC . getField ( field ) . type , } ) ; } else { childTC . setField ( field , baseDTC . getField ( field ) ) ; } } return childTC ; } export function composeChildTC < TSource , TContext > ( baseDTC , childTC , opts ) { let composedChildTC = copyBaseTcRelationsToChildTc ( baseDTC , childTC ) ; composedChildTC = copyBaseTCFieldsToChildTC ( baseDTC , composedChildTC ) ; composedChildTC . addInterface ( baseDTC . getDInterface ( ) ) ; prepareChildResolvers ( baseDTC , composedChildTC , opts ) ; reorderFields ( composedChildTC , opts . reorderFields , baseDTC . getDKey ( ) , baseDTC . getFieldNames ( ) ) ; return composedChildTC ; }