@graphql-codegen/typescript-operations 4.6.2-alpha-20250509134235-30ac8930f49f44ab10e6b7dcdd7f12a67bfa9fc4 → 4.6.2-alpha-20250529121049-5e08c758900167a8eaee6ff178599c2b990bf21d
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.
|
@@ -12,19 +12,19 @@ class TypeScriptSelectionSetProcessor extends visitor_plugin_common_1.BaseSelect
|
|
|
12
12
|
useTypesPrefix: true,
|
|
13
13
|
});
|
|
14
14
|
if (unsetTypes) {
|
|
15
|
-
|
|
15
|
+
const escapedFieldNames = fields.map(field => `'${field.fieldName}'`);
|
|
16
|
+
return [formattedUnionTransform('MakeEmpty', parentName, escapedFieldNames)];
|
|
16
17
|
}
|
|
17
18
|
let hasConditionals = false;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
.map(field => {
|
|
19
|
+
const escapedConditionalsList = [];
|
|
20
|
+
const escapedFieldNames = fields.map(field => {
|
|
21
21
|
if (field.isConditional) {
|
|
22
22
|
hasConditionals = true;
|
|
23
|
-
|
|
23
|
+
escapedConditionalsList.push(`'${field.fieldName}'`);
|
|
24
24
|
}
|
|
25
25
|
return `'${field.fieldName}'`;
|
|
26
|
-
})
|
|
27
|
-
|
|
26
|
+
});
|
|
27
|
+
let resString = formattedUnionTransform('Pick', parentName, escapedFieldNames);
|
|
28
28
|
if (hasConditionals) {
|
|
29
29
|
const avoidOptional =
|
|
30
30
|
// TODO: check type and exec only if relevant
|
|
@@ -34,7 +34,7 @@ class TypeScriptSelectionSetProcessor extends visitor_plugin_common_1.BaseSelect
|
|
|
34
34
|
this.config.avoidOptionals.inputValue ||
|
|
35
35
|
this.config.avoidOptionals.object));
|
|
36
36
|
const transform = avoidOptional ? 'MakeMaybe' : 'MakeOptional';
|
|
37
|
-
resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${transform
|
|
37
|
+
resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform(transform, resString, escapedConditionalsList)}`;
|
|
38
38
|
}
|
|
39
39
|
return [resString];
|
|
40
40
|
}
|
|
@@ -49,22 +49,32 @@ class TypeScriptSelectionSetProcessor extends visitor_plugin_common_1.BaseSelect
|
|
|
49
49
|
this.config.convertName(schemaType.name, {
|
|
50
50
|
useTypesPrefix: true,
|
|
51
51
|
});
|
|
52
|
-
|
|
53
|
-
`{ ${
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
: `${parentName}['${aliasedField.fieldName}']`;
|
|
58
|
-
return `${aliasedField.alias}: ${value}`;
|
|
59
|
-
})
|
|
60
|
-
.join(', ')} }`,
|
|
61
|
-
];
|
|
52
|
+
const selections = fields.map(aliasedField => {
|
|
53
|
+
const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
|
|
54
|
+
return `${aliasedField.alias}: ${value}`;
|
|
55
|
+
});
|
|
56
|
+
return [formatSelections(selections)];
|
|
62
57
|
}
|
|
63
58
|
transformLinkFields(fields) {
|
|
64
59
|
if (fields.length === 0) {
|
|
65
60
|
return [];
|
|
66
61
|
}
|
|
67
|
-
|
|
62
|
+
const selections = fields.map(field => `${field.alias || field.name}: ${field.selectionSet}`);
|
|
63
|
+
return [formatSelections(selections)];
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
exports.TypeScriptSelectionSetProcessor = TypeScriptSelectionSetProcessor;
|
|
67
|
+
/** Equivalent to `${transformName}<${target}, ${unionElements.join(' | ')}>`, but with line feeds if necessary */
|
|
68
|
+
function formattedUnionTransform(transformName, target, unionElements) {
|
|
69
|
+
if (unionElements.length > 3) {
|
|
70
|
+
return `${transformName}<\n ${target},\n | ${unionElements.join('\n | ')}\n >`;
|
|
71
|
+
}
|
|
72
|
+
return `${transformName}<${target}, ${unionElements.join(' | ')}>`;
|
|
73
|
+
}
|
|
74
|
+
/** Equivalent to `{ ${selections.join(', ')} }`, but with line feeds if necessary */
|
|
75
|
+
function formatSelections(selections) {
|
|
76
|
+
if (selections.length > 1) {
|
|
77
|
+
return `{\n ${selections.map(s => s.replace(/\n/g, '\n ')).join(',\n ')},\n }`;
|
|
78
|
+
}
|
|
79
|
+
return `{ ${selections.join(', ')} }`;
|
|
80
|
+
}
|
|
@@ -9,19 +9,19 @@ export class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor {
|
|
|
9
9
|
useTypesPrefix: true,
|
|
10
10
|
});
|
|
11
11
|
if (unsetTypes) {
|
|
12
|
-
|
|
12
|
+
const escapedFieldNames = fields.map(field => `'${field.fieldName}'`);
|
|
13
|
+
return [formattedUnionTransform('MakeEmpty', parentName, escapedFieldNames)];
|
|
13
14
|
}
|
|
14
15
|
let hasConditionals = false;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
.map(field => {
|
|
16
|
+
const escapedConditionalsList = [];
|
|
17
|
+
const escapedFieldNames = fields.map(field => {
|
|
18
18
|
if (field.isConditional) {
|
|
19
19
|
hasConditionals = true;
|
|
20
|
-
|
|
20
|
+
escapedConditionalsList.push(`'${field.fieldName}'`);
|
|
21
21
|
}
|
|
22
22
|
return `'${field.fieldName}'`;
|
|
23
|
-
})
|
|
24
|
-
|
|
23
|
+
});
|
|
24
|
+
let resString = formattedUnionTransform('Pick', parentName, escapedFieldNames);
|
|
25
25
|
if (hasConditionals) {
|
|
26
26
|
const avoidOptional =
|
|
27
27
|
// TODO: check type and exec only if relevant
|
|
@@ -31,7 +31,7 @@ export class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor {
|
|
|
31
31
|
this.config.avoidOptionals.inputValue ||
|
|
32
32
|
this.config.avoidOptionals.object));
|
|
33
33
|
const transform = avoidOptional ? 'MakeMaybe' : 'MakeOptional';
|
|
34
|
-
resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${transform
|
|
34
|
+
resString = `${this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''}${formattedUnionTransform(transform, resString, escapedConditionalsList)}`;
|
|
35
35
|
}
|
|
36
36
|
return [resString];
|
|
37
37
|
}
|
|
@@ -46,21 +46,31 @@ export class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor {
|
|
|
46
46
|
this.config.convertName(schemaType.name, {
|
|
47
47
|
useTypesPrefix: true,
|
|
48
48
|
});
|
|
49
|
-
|
|
50
|
-
`{ ${
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
: `${parentName}['${aliasedField.fieldName}']`;
|
|
55
|
-
return `${aliasedField.alias}: ${value}`;
|
|
56
|
-
})
|
|
57
|
-
.join(', ')} }`,
|
|
58
|
-
];
|
|
49
|
+
const selections = fields.map(aliasedField => {
|
|
50
|
+
const value = aliasedField.fieldName === '__typename' ? `'${schemaType.name}'` : `${parentName}['${aliasedField.fieldName}']`;
|
|
51
|
+
return `${aliasedField.alias}: ${value}`;
|
|
52
|
+
});
|
|
53
|
+
return [formatSelections(selections)];
|
|
59
54
|
}
|
|
60
55
|
transformLinkFields(fields) {
|
|
61
56
|
if (fields.length === 0) {
|
|
62
57
|
return [];
|
|
63
58
|
}
|
|
64
|
-
|
|
59
|
+
const selections = fields.map(field => `${field.alias || field.name}: ${field.selectionSet}`);
|
|
60
|
+
return [formatSelections(selections)];
|
|
65
61
|
}
|
|
66
62
|
}
|
|
63
|
+
/** Equivalent to `${transformName}<${target}, ${unionElements.join(' | ')}>`, but with line feeds if necessary */
|
|
64
|
+
function formattedUnionTransform(transformName, target, unionElements) {
|
|
65
|
+
if (unionElements.length > 3) {
|
|
66
|
+
return `${transformName}<\n ${target},\n | ${unionElements.join('\n | ')}\n >`;
|
|
67
|
+
}
|
|
68
|
+
return `${transformName}<${target}, ${unionElements.join(' | ')}>`;
|
|
69
|
+
}
|
|
70
|
+
/** Equivalent to `{ ${selections.join(', ')} }`, but with line feeds if necessary */
|
|
71
|
+
function formatSelections(selections) {
|
|
72
|
+
if (selections.length > 1) {
|
|
73
|
+
return `{\n ${selections.map(s => s.replace(/\n/g, '\n ')).join(',\n ')},\n }`;
|
|
74
|
+
}
|
|
75
|
+
return `{ ${selections.join(', ')} }`;
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-operations",
|
|
3
|
-
"version": "4.6.2-alpha-
|
|
3
|
+
"version": "4.6.2-alpha-20250529121049-5e08c758900167a8eaee6ff178599c2b990bf21d",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating TypeScript types for GraphQL queries, mutations, subscriptions and fragments",
|
|
5
5
|
"peerDependenciesMeta": {
|
|
6
6
|
"graphql-sock": {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"graphql-sock": "^1.0.0"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-
|
|
16
|
-
"@graphql-codegen/typescript": "4.1.7-alpha-
|
|
17
|
-
"@graphql-codegen/visitor-plugin-common": "6.0.0-alpha-
|
|
15
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250529121049-5e08c758900167a8eaee6ff178599c2b990bf21d",
|
|
16
|
+
"@graphql-codegen/typescript": "4.1.7-alpha-20250529121049-5e08c758900167a8eaee6ff178599c2b990bf21d",
|
|
17
|
+
"@graphql-codegen/visitor-plugin-common": "6.0.0-alpha-20250529121049-5e08c758900167a8eaee6ff178599c2b990bf21d",
|
|
18
18
|
"auto-bind": "~4.0.0",
|
|
19
19
|
"tslib": "~2.6.0"
|
|
20
20
|
},
|