@@ -1105,54 +1105,58 @@ export class BaseResolversVisitor<
1105
1105
memberTypes : readonly GraphQLObjectType [ ] | GraphQLObjectType [ ] ;
1106
1106
isTypenameNonOptional : boolean ;
1107
1107
} ) : string {
1108
- const result =
1109
- memberTypes
1110
- . map ( type => {
1111
- const isTypeMapped = this . config . mappers [ type . name ] ;
1112
- // 1. If mapped without placehoder, just use it without doing extra checks
1113
- if ( isTypeMapped && ! hasPlaceholder ( isTypeMapped . type ) ) {
1114
- return { typename : type . name , typeValue : isTypeMapped . type } ;
1115
- }
1108
+ const members = memberTypes
1109
+ . map ( type => {
1110
+ const isTypeMapped = this . config . mappers [ type . name ] ;
1111
+ // 1. If mapped without placehoder, just use it without doing extra checks
1112
+ if ( isTypeMapped && ! hasPlaceholder ( isTypeMapped . type ) ) {
1113
+ return { typename : type . name , typeValue : isTypeMapped . type } ;
1114
+ }
1116
1115
1117
- // 2. Work out value for type
1118
- // 2a. By default, use the typescript type
1119
- let typeValue = this . convertName ( type . name , { } , true ) ;
1116
+ // 2. Work out value for type
1117
+ // 2a. By default, use the typescript type
1118
+ let typeValue = this . convertName ( type . name , { } , true ) ;
1120
1119
1121
- // 2b. Find fields to Omit if needed.
1122
- // - If no field to Omit, "type with maybe Omit" is typescript type i.e. no Omit
1123
- // - If there are fields to Omit, keep track of these "type with maybe Omit" to replace in original unionMemberValue
1124
- const fieldsToOmit = this . getRelevantFieldsToOmit ( {
1125
- schemaType : type ,
1126
- getTypeToUse : baseType => `_RefType['${ baseType } ']` ,
1127
- } ) ;
1128
- if ( fieldsToOmit . length > 0 ) {
1129
- typeValue = this . replaceFieldsInType ( typeValue , fieldsToOmit ) ;
1130
- }
1120
+ // 2b. Find fields to Omit if needed.
1121
+ // - If no field to Omit, "type with maybe Omit" is typescript type i.e. no Omit
1122
+ // - If there are fields to Omit, keep track of these "type with maybe Omit" to replace in original unionMemberValue
1123
+ const fieldsToOmit = this . getRelevantFieldsToOmit ( {
1124
+ schemaType : type ,
1125
+ getTypeToUse : baseType => `_RefType['${ baseType } ']` ,
1126
+ } ) ;
1127
+ if ( fieldsToOmit . length > 0 ) {
1128
+ typeValue = this . replaceFieldsInType ( typeValue , fieldsToOmit ) ;
1129
+ }
1131
1130
1132
- // 2c. If type is mapped with placeholder, use the "type with maybe Omit" as {T}
1133
- if ( isTypeMapped && hasPlaceholder ( isTypeMapped . type ) ) {
1134
- return { typename : type . name , typeValue : replacePlaceholder ( isTypeMapped . type , typeValue ) } ;
1135
- }
1131
+ // 2c. If type is mapped with placeholder, use the "type with maybe Omit" as {T}
1132
+ if ( isTypeMapped && hasPlaceholder ( isTypeMapped . type ) ) {
1133
+ return { typename : type . name , typeValue : replacePlaceholder ( isTypeMapped . type , typeValue ) } ;
1134
+ }
1136
1135
1137
- // 2d. If has default mapper with placeholder, use the "type with maybe Omit" as {T}
1138
- const hasDefaultMapper = ! ! this . config . defaultMapper ?. type ;
1139
- const isScalar = this . config . scalars [ typeName ] ;
1140
- if ( hasDefaultMapper && hasPlaceholder ( this . config . defaultMapper . type ) ) {
1141
- const finalTypename = isScalar ? this . _getScalar ( typeName ) : typeValue ;
1142
- return {
1143
- typename : type . name ,
1144
- typeValue : replacePlaceholder ( this . config . defaultMapper . type , finalTypename ) ,
1145
- } ;
1146
- }
1136
+ // 2d. If has default mapper with placeholder, use the "type with maybe Omit" as {T}
1137
+ const hasDefaultMapper = ! ! this . config . defaultMapper ?. type ;
1138
+ const isScalar = this . config . scalars [ typeName ] ;
1139
+ if ( hasDefaultMapper && hasPlaceholder ( this . config . defaultMapper . type ) ) {
1140
+ const finalTypename = isScalar ? this . _getScalar ( typeName ) : typeValue ;
1141
+ return {
1142
+ typename : type . name ,
1143
+ typeValue : replacePlaceholder ( this . config . defaultMapper . type , finalTypename ) ,
1144
+ } ;
1145
+ }
1147
1146
1148
- return { typename : type . name , typeValue } ;
1149
- } )
1150
- . map ( ( { typename, typeValue } ) => {
1151
- const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${ typename } ' }` : '' ;
1147
+ return { typename : type . name , typeValue } ;
1148
+ } )
1149
+ . map ( ( { typename, typeValue } ) => {
1150
+ const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${ typename } ' }` : '' ;
1152
1151
1153
- return `( ${ typeValue } ${ nonOptionalTypenameModifier } )` ; // Must wrap every type in explicit "( )" to separate them
1154
- } )
1155
- . join ( ' | ' ) || 'never' ;
1152
+ return `( ${ typeValue } ${ nonOptionalTypenameModifier } )` ; // Must wrap every type in explicit "( )" to separate them
1153
+ } ) ;
1154
+ const result =
1155
+ members . length === 0
1156
+ ? 'never'
1157
+ : members . length > 1
1158
+ ? `\n | ${ members . map ( m => m . replace ( / \n / g, '\n ' ) ) . join ( '\n | ' ) } \n `
1159
+ : members . join ( ' | ' ) ;
1156
1160
return result ;
1157
1161
}
1158
1162
0 commit comments