@graphql-codegen/visitor-plugin-common 5.8.0 → 5.8.1-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -315,7 +315,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
315
315
|
* Function to generate the types of Abstract Type Members i.e. Union Members or Interface Implementing Types
|
|
316
316
|
*/
|
|
317
317
|
getAbstractMembersType({ typeName, memberTypes, isTypenameNonOptional, }) {
|
|
318
|
-
const
|
|
318
|
+
const members = memberTypes
|
|
319
319
|
.map(type => {
|
|
320
320
|
const isTypeMapped = this.config.mappers[type.name];
|
|
321
321
|
// 1. If mapped without placehoder, just use it without doing extra checks
|
|
@@ -354,8 +354,12 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
354
354
|
.map(({ typename, typeValue }) => {
|
|
355
355
|
const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${typename}' }` : '';
|
|
356
356
|
return `( ${typeValue}${nonOptionalTypenameModifier} )`; // Must wrap every type in explicit "( )" to separate them
|
|
357
|
-
})
|
|
358
|
-
|
|
357
|
+
});
|
|
358
|
+
const result = members.length === 0
|
|
359
|
+
? 'never'
|
|
360
|
+
: members.length > 1
|
|
361
|
+
? `\n | ${members.map(m => m.replace(/\n/g, '\n ')).join('\n | ')}\n `
|
|
362
|
+
: members.join(' | ');
|
|
359
363
|
return result;
|
|
360
364
|
}
|
|
361
365
|
createFieldContextTypeMap() {
|
|
@@ -589,7 +589,7 @@ class SelectionSetToObject {
|
|
|
589
589
|
.join(' & ')),
|
|
590
590
|
this.getEmptyObjectTypeString(mustAddEmptyObject),
|
|
591
591
|
].filter(Boolean);
|
|
592
|
-
const content = typeParts
|
|
592
|
+
const content = formatUnion(typeParts);
|
|
593
593
|
if (typeParts.length > 1 && this._config.extractAllFieldsToTypes) {
|
|
594
594
|
return {
|
|
595
595
|
mergedTypeString: fieldName,
|
|
@@ -662,7 +662,7 @@ class SelectionSetToObject {
|
|
|
662
662
|
.export()
|
|
663
663
|
.asKind('type')
|
|
664
664
|
.withName(mergedTypeString)
|
|
665
|
-
.withContent(subTypes.map(t => t.name)
|
|
665
|
+
.withContent(formatUnion(subTypes.map(t => t.name))).string,
|
|
666
666
|
].join('\n');
|
|
667
667
|
}
|
|
668
668
|
buildFragmentTypeName(name, suffix, typeName = '') {
|
|
@@ -678,3 +678,9 @@ class SelectionSetToObject {
|
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
680
|
exports.SelectionSetToObject = SelectionSetToObject;
|
|
681
|
+
function formatUnion(members) {
|
|
682
|
+
if (members.length > 1) {
|
|
683
|
+
return `\n | ${members.map(m => m.replace(/\n/g, '\n ')).join('\n | ')}\n`;
|
|
684
|
+
}
|
|
685
|
+
return members.join(' | ');
|
|
686
|
+
}
|
|
@@ -311,7 +311,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
311
311
|
* Function to generate the types of Abstract Type Members i.e. Union Members or Interface Implementing Types
|
|
312
312
|
*/
|
|
313
313
|
getAbstractMembersType({ typeName, memberTypes, isTypenameNonOptional, }) {
|
|
314
|
-
const
|
|
314
|
+
const members = memberTypes
|
|
315
315
|
.map(type => {
|
|
316
316
|
const isTypeMapped = this.config.mappers[type.name];
|
|
317
317
|
// 1. If mapped without placehoder, just use it without doing extra checks
|
|
@@ -350,8 +350,12 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
350
350
|
.map(({ typename, typeValue }) => {
|
|
351
351
|
const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${typename}' }` : '';
|
|
352
352
|
return `( ${typeValue}${nonOptionalTypenameModifier} )`; // Must wrap every type in explicit "( )" to separate them
|
|
353
|
-
})
|
|
354
|
-
|
|
353
|
+
});
|
|
354
|
+
const result = members.length === 0
|
|
355
|
+
? 'never'
|
|
356
|
+
: members.length > 1
|
|
357
|
+
? `\n | ${members.map(m => m.replace(/\n/g, '\n ')).join('\n | ')}\n `
|
|
358
|
+
: members.join(' | ');
|
|
355
359
|
return result;
|
|
356
360
|
}
|
|
357
361
|
createFieldContextTypeMap() {
|
|
@@ -585,7 +585,7 @@ export class SelectionSetToObject {
|
|
|
585
585
|
.join(' & ')),
|
|
586
586
|
this.getEmptyObjectTypeString(mustAddEmptyObject),
|
|
587
587
|
].filter(Boolean);
|
|
588
|
-
const content = typeParts
|
|
588
|
+
const content = formatUnion(typeParts);
|
|
589
589
|
if (typeParts.length > 1 && this._config.extractAllFieldsToTypes) {
|
|
590
590
|
return {
|
|
591
591
|
mergedTypeString: fieldName,
|
|
@@ -658,7 +658,7 @@ export class SelectionSetToObject {
|
|
|
658
658
|
.export()
|
|
659
659
|
.asKind('type')
|
|
660
660
|
.withName(mergedTypeString)
|
|
661
|
-
.withContent(subTypes.map(t => t.name)
|
|
661
|
+
.withContent(formatUnion(subTypes.map(t => t.name))).string,
|
|
662
662
|
].join('\n');
|
|
663
663
|
}
|
|
664
664
|
buildFragmentTypeName(name, suffix, typeName = '') {
|
|
@@ -673,3 +673,9 @@ export class SelectionSetToObject {
|
|
|
673
673
|
return operationTypes.includes(typeName) ? parentName : `${parentName}_${typeName}`;
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
|
+
function formatUnion(members) {
|
|
677
|
+
if (members.length > 1) {
|
|
678
|
+
return `\n | ${members.map(m => m.replace(/\n/g, '\n ')).join('\n | ')}\n`;
|
|
679
|
+
}
|
|
680
|
+
return members.join(' | ');
|
|
681
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/visitor-plugin-common",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.1-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@graphql-tools/optimize": "^2.0.0",
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66",
|
|
10
10
|
"@graphql-tools/relay-operation-optimizer": "^7.0.0",
|
|
11
11
|
"@graphql-tools/utils": "^10.0.0",
|
|
12
12
|
"auto-bind": "~4.0.0",
|