@@ -1128,54 +1128,58 @@ export class BaseResolversVisitor<
1128
1128
memberTypes : readonly GraphQLObjectType [ ] | GraphQLObjectType [ ] ;
1129
1129
isTypenameNonOptional : boolean ;
1130
1130
} ) : string {
1131
- const result =
1132
- memberTypes
1133
- . map ( type => {
1134
- const isTypeMapped = this . config . mappers [ type . name ] ;
1135
- // 1. If mapped without placehoder, just use it without doing extra checks
1136
- if ( isTypeMapped && ! hasPlaceholder ( isTypeMapped . type ) ) {
1137
- return { typename : type . name , typeValue : isTypeMapped . type } ;
1138
- }
1131
+ const members = memberTypes
1132
+ . map ( type => {
1133
+ const isTypeMapped = this . config . mappers [ type . name ] ;
1134
+ // 1. If mapped without placehoder, just use it without doing extra checks
1135
+ if ( isTypeMapped && ! hasPlaceholder ( isTypeMapped . type ) ) {
1136
+ return { typename : type . name , typeValue : isTypeMapped . type } ;
1137
+ }
1139
1138
1140
- // 2. Work out value for type
1141
- // 2a. By default, use the typescript type
1142
- let typeValue = this . convertName ( type . name , { } , true ) ;
1139
+ // 2. Work out value for type
1140
+ // 2a. By default, use the typescript type
1141
+ let typeValue = this . convertName ( type . name , { } , true ) ;
1143
1142
1144
- // 2b. Find fields to Omit if needed.
1145
- // - If no field to Omit, "type with maybe Omit" is typescript type i.e. no Omit
1146
- // - If there are fields to Omit, keep track of these "type with maybe Omit" to replace in original unionMemberValue
1147
- const fieldsToOmit = this . getRelevantFieldsToOmit ( {
1148
- schemaType : type ,
1149
- getTypeToUse : baseType => `_RefType['${ baseType } ']` ,
1150
- } ) ;
1151
- if ( fieldsToOmit . length > 0 ) {
1152
- typeValue = this . replaceFieldsInType ( typeValue , fieldsToOmit ) ;
1153
- }
1143
+ // 2b. Find fields to Omit if needed.
1144
+ // - If no field to Omit, "type with maybe Omit" is typescript type i.e. no Omit
1145
+ // - If there are fields to Omit, keep track of these "type with maybe Omit" to replace in original unionMemberValue
1146
+ const fieldsToOmit = this . getRelevantFieldsToOmit ( {
1147
+ schemaType : type ,
1148
+ getTypeToUse : baseType => `_RefType['${ baseType } ']` ,
1149
+ } ) ;
1150
+ if ( fieldsToOmit . length > 0 ) {
1151
+ typeValue = this . replaceFieldsInType ( typeValue , fieldsToOmit ) ;
1152
+ }
1154
1153
1155
- // 2c. If type is mapped with placeholder, use the "type with maybe Omit" as {T}
1156
- if ( isTypeMapped && hasPlaceholder ( isTypeMapped . type ) ) {
1157
- return { typename : type . name , typeValue : replacePlaceholder ( isTypeMapped . type , typeValue ) } ;
1158
- }
1154
+ // 2c. If type is mapped with placeholder, use the "type with maybe Omit" as {T}
1155
+ if ( isTypeMapped && hasPlaceholder ( isTypeMapped . type ) ) {
1156
+ return { typename : type . name , typeValue : replacePlaceholder ( isTypeMapped . type , typeValue ) } ;
1157
+ }
1159
1158
1160
- // 2d. If has default mapper with placeholder, use the "type with maybe Omit" as {T}
1161
- const hasDefaultMapper = ! ! this . config . defaultMapper ?. type ;
1162
- const isScalar = this . config . scalars [ typeName ] ;
1163
- if ( hasDefaultMapper && hasPlaceholder ( this . config . defaultMapper . type ) ) {
1164
- const finalTypename = isScalar ? this . _getScalar ( typeName ) : typeValue ;
1165
- return {
1166
- typename : type . name ,
1167
- typeValue : replacePlaceholder ( this . config . defaultMapper . type , finalTypename ) ,
1168
- } ;
1169
- }
1159
+ // 2d. If has default mapper with placeholder, use the "type with maybe Omit" as {T}
1160
+ const hasDefaultMapper = ! ! this . config . defaultMapper ?. type ;
1161
+ const isScalar = this . config . scalars [ typeName ] ;
1162
+ if ( hasDefaultMapper && hasPlaceholder ( this . config . defaultMapper . type ) ) {
1163
+ const finalTypename = isScalar ? this . _getScalar ( typeName ) : typeValue ;
1164
+ return {
1165
+ typename : type . name ,
1166
+ typeValue : replacePlaceholder ( this . config . defaultMapper . type , finalTypename ) ,
1167
+ } ;
1168
+ }
1170
1169
1171
- return { typename : type . name , typeValue } ;
1172
- } )
1173
- . map ( ( { typename, typeValue } ) => {
1174
- const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${ typename } ' }` : '' ;
1170
+ return { typename : type . name , typeValue } ;
1171
+ } )
1172
+ . map ( ( { typename, typeValue } ) => {
1173
+ const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${ typename } ' }` : '' ;
1175
1174
1176
- return `( ${ typeValue } ${ nonOptionalTypenameModifier } )` ; // Must wrap every type in explicit "( )" to separate them
1177
- } )
1178
- . join ( ' | ' ) || 'never' ;
1175
+ return `( ${ typeValue } ${ nonOptionalTypenameModifier } )` ; // Must wrap every type in explicit "( )" to separate them
1176
+ } ) ;
1177
+ const result =
1178
+ members . length === 0
1179
+ ? 'never'
1180
+ : members . length > 1
1181
+ ? `\n | ${ members . map ( m => m . replace ( / \n / g, '\n ' ) ) . join ( '\n | ' ) } \n `
1182
+ : members . join ( ' | ' ) ;
1179
1183
return result ;
1180
1184
}
1181
1185
0 commit comments