@graphql-codegen/visitor-plugin-common 6.0.0-alpha-20250522111047-b446e84383ba57bc9f768b55db1e0ccf958a27c3 → 6.0.0-alpha-20250605130257-1e7b946935178b3b974e69e9ee07aba437d33e95
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.
|
@@ -328,7 +328,7 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
328
328
|
* Function to generate the types of Abstract Type Members i.e. Union Members or Interface Implementing Types
|
|
329
329
|
*/
|
|
330
330
|
getAbstractMembersType({ typeName, memberTypes, isTypenameNonOptional, }) {
|
|
331
|
-
const
|
|
331
|
+
const members = memberTypes
|
|
332
332
|
.map(type => {
|
|
333
333
|
const isTypeMapped = this.config.mappers[type.name];
|
|
334
334
|
// 1. If mapped without placehoder, just use it without doing extra checks
|
|
@@ -367,8 +367,12 @@ class BaseResolversVisitor extends base_visitor_js_1.BaseVisitor {
|
|
|
367
367
|
.map(({ typename, typeValue }) => {
|
|
368
368
|
const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${typename}' }` : '';
|
|
369
369
|
return `( ${typeValue}${nonOptionalTypenameModifier} )`; // Must wrap every type in explicit "( )" to separate them
|
|
370
|
-
})
|
|
371
|
-
|
|
370
|
+
});
|
|
371
|
+
const result = members.length === 0
|
|
372
|
+
? 'never'
|
|
373
|
+
: members.length > 1
|
|
374
|
+
? `\n | ${members.map(m => m.replace(/\n/g, '\n ')).join('\n | ')}\n `
|
|
375
|
+
: members.join(' | ');
|
|
372
376
|
return result;
|
|
373
377
|
}
|
|
374
378
|
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
|
+
}
|
|
@@ -324,7 +324,7 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
324
324
|
* Function to generate the types of Abstract Type Members i.e. Union Members or Interface Implementing Types
|
|
325
325
|
*/
|
|
326
326
|
getAbstractMembersType({ typeName, memberTypes, isTypenameNonOptional, }) {
|
|
327
|
-
const
|
|
327
|
+
const members = memberTypes
|
|
328
328
|
.map(type => {
|
|
329
329
|
const isTypeMapped = this.config.mappers[type.name];
|
|
330
330
|
// 1. If mapped without placehoder, just use it without doing extra checks
|
|
@@ -363,8 +363,12 @@ export class BaseResolversVisitor extends BaseVisitor {
|
|
|
363
363
|
.map(({ typename, typeValue }) => {
|
|
364
364
|
const nonOptionalTypenameModifier = isTypenameNonOptional ? ` & { __typename: '${typename}' }` : '';
|
|
365
365
|
return `( ${typeValue}${nonOptionalTypenameModifier} )`; // Must wrap every type in explicit "( )" to separate them
|
|
366
|
-
})
|
|
367
|
-
|
|
366
|
+
});
|
|
367
|
+
const result = members.length === 0
|
|
368
|
+
? 'never'
|
|
369
|
+
: members.length > 1
|
|
370
|
+
? `\n | ${members.map(m => m.replace(/\n/g, '\n ')).join('\n | ')}\n `
|
|
371
|
+
: members.join(' | ');
|
|
368
372
|
return result;
|
|
369
373
|
}
|
|
370
374
|
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": "6.0.0-alpha-
|
|
3
|
+
"version": "6.0.0-alpha-20250605130257-1e7b946935178b3b974e69e9ee07aba437d33e95",
|
|
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": "6.0.0-alpha-
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250605130257-1e7b946935178b3b974e69e9ee07aba437d33e95",
|
|
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",
|