@graphql-codegen/typescript-operations 6.1.10 → 6.2.0-alpha-20261020121858-c3944e938bd6f39aa8a40fa42ce20141955210c7
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.
- package/cjs/ts-operation-variables-to-object.js +3 -0
- package/cjs/visitor.js +5 -0
- package/esm/ts-operation-variables-to-object.js +3 -0
- package/esm/visitor.js +5 -0
- package/package.json +4 -4
- package/typings/config.d.cts +6 -1
- package/typings/config.d.ts +6 -1
- package/typings/ts-operation-variables-to-object.d.cts +1 -0
- package/typings/ts-operation-variables-to-object.d.ts +1 -0
|
@@ -43,6 +43,9 @@ class TypeScriptOperationVariablesToObject extends visitor_plugin_common_1.Opera
|
|
|
43
43
|
const listInputCoercionExtension = applyCoercion ? ` | ${innerType}` : '';
|
|
44
44
|
return this.wrapMaybe(`${this._config.immutableTypes ? 'ReadonlyArray' : 'Array'}<${innerType}>${listInputCoercionExtension}`);
|
|
45
45
|
}
|
|
46
|
+
if (this._config.enumWithStringValues && this._enumNames.includes(typeNode.name.value)) {
|
|
47
|
+
return this.wrapMaybe(`${baseType} | \`\${${baseType}}\``);
|
|
48
|
+
}
|
|
46
49
|
return this.wrapMaybe(baseType);
|
|
47
50
|
}
|
|
48
51
|
wrapMaybe(type) {
|
package/cjs/visitor.js
CHANGED
|
@@ -137,6 +137,7 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
|
|
|
137
137
|
avoidOptionals: this.config.avoidOptionals,
|
|
138
138
|
immutableTypes: this.config.immutableTypes,
|
|
139
139
|
inputMaybeValue: this.config.inputMaybeValue,
|
|
140
|
+
enumWithStringValues: this.config.enumType === 'native-with-string-values',
|
|
140
141
|
}, this.scalars, this.convertName.bind(this), this.config.namespacedImportName, enumsNames, this.config.enumPrefix, this.config.enumSuffix, this.config.enumValues, this.config.arrayInputCoercion));
|
|
141
142
|
this._declarationBlockConfig = {
|
|
142
143
|
ignoreExport: this.config.noExport,
|
|
@@ -231,6 +232,10 @@ class TypeScriptDocumentsVisitor extends visitor_plugin_common_1.BaseDocumentsVi
|
|
|
231
232
|
continue;
|
|
232
233
|
}
|
|
233
234
|
typePart = usedInputType.tsType; // If the schema is correct, when reversing typeNodes, the first node would be `NamedType`, which means we can safely set it as the base for typePart
|
|
235
|
+
if (usedInputType.type === 'GraphQLEnumType' &&
|
|
236
|
+
this.config.enumType === 'native-with-string-values') {
|
|
237
|
+
typePart = `${typePart} | \`\${${typePart}}\``;
|
|
238
|
+
}
|
|
234
239
|
if (!typeNode.isNonNullable) {
|
|
235
240
|
typePart = (0, visitor_plugin_common_1.printTypeScriptMaybeType)({
|
|
236
241
|
type: typePart,
|
|
@@ -40,6 +40,9 @@ export class TypeScriptOperationVariablesToObject extends OperationVariablesToOb
|
|
|
40
40
|
const listInputCoercionExtension = applyCoercion ? ` | ${innerType}` : '';
|
|
41
41
|
return this.wrapMaybe(`${this._config.immutableTypes ? 'ReadonlyArray' : 'Array'}<${innerType}>${listInputCoercionExtension}`);
|
|
42
42
|
}
|
|
43
|
+
if (this._config.enumWithStringValues && this._enumNames.includes(typeNode.name.value)) {
|
|
44
|
+
return this.wrapMaybe(`${baseType} | \`\${${baseType}}\``);
|
|
45
|
+
}
|
|
43
46
|
return this.wrapMaybe(baseType);
|
|
44
47
|
}
|
|
45
48
|
wrapMaybe(type) {
|
package/esm/visitor.js
CHANGED
|
@@ -133,6 +133,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
|
|
|
133
133
|
avoidOptionals: this.config.avoidOptionals,
|
|
134
134
|
immutableTypes: this.config.immutableTypes,
|
|
135
135
|
inputMaybeValue: this.config.inputMaybeValue,
|
|
136
|
+
enumWithStringValues: this.config.enumType === 'native-with-string-values',
|
|
136
137
|
}, this.scalars, this.convertName.bind(this), this.config.namespacedImportName, enumsNames, this.config.enumPrefix, this.config.enumSuffix, this.config.enumValues, this.config.arrayInputCoercion));
|
|
137
138
|
this._declarationBlockConfig = {
|
|
138
139
|
ignoreExport: this.config.noExport,
|
|
@@ -227,6 +228,10 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor {
|
|
|
227
228
|
continue;
|
|
228
229
|
}
|
|
229
230
|
typePart = usedInputType.tsType; // If the schema is correct, when reversing typeNodes, the first node would be `NamedType`, which means we can safely set it as the base for typePart
|
|
231
|
+
if (usedInputType.type === 'GraphQLEnumType' &&
|
|
232
|
+
this.config.enumType === 'native-with-string-values') {
|
|
233
|
+
typePart = `${typePart} | \`\${${typePart}}\``;
|
|
234
|
+
}
|
|
230
235
|
if (!typeNode.isNonNullable) {
|
|
231
236
|
typePart = printTypeScriptMaybeType({
|
|
232
237
|
type: typePart,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/typescript-operations",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0-alpha-20261020121858-c3944e938bd6f39aa8a40fa42ce20141955210c7",
|
|
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": "^7.4.
|
|
16
|
-
"@graphql-codegen/schema-ast": "^6.1.
|
|
17
|
-
"@graphql-codegen/visitor-plugin-common": "^7.
|
|
15
|
+
"@graphql-codegen/plugin-helpers": "^7.4.2",
|
|
16
|
+
"@graphql-codegen/schema-ast": "^6.1.1",
|
|
17
|
+
"@graphql-codegen/visitor-plugin-common": "^7.4.0-alpha-20261020121858-c3944e938bd6f39aa8a40fa42ce20141955210c7",
|
|
18
18
|
"auto-bind": "^5.0.0",
|
|
19
19
|
"tslib": "^2.8.0"
|
|
20
20
|
},
|
package/typings/config.d.cts
CHANGED
|
@@ -310,7 +310,12 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
|
|
|
310
310
|
errorHandlingClient: boolean;
|
|
311
311
|
};
|
|
312
312
|
/**
|
|
313
|
-
* @description Controls the enum output type. Options: `string-literal` | `native-numeric` | `const` | `native-const` | `native`;
|
|
313
|
+
* @description Controls the enum output type. Options: `string-literal` | `native-numeric` | `const` | `native-const` | `native` | `native-with-string-values`;
|
|
314
|
+
*
|
|
315
|
+
* `native-with-string-values` declares enums the same way as `native`, and types enums in operation variables and input object fields as ``E | `${E}` ``,
|
|
316
|
+
* so either the enum member or its string value can be passed, e.g. `TargetType.A` or `'A'`.
|
|
317
|
+
* Enums in operation result types stay `E`.
|
|
318
|
+
* Note: if `enumValues` maps an enum's values to numbers, `` `${E}` `` yields their string forms, e.g. `'0' | '1'`.
|
|
314
319
|
* @default `string-literal`
|
|
315
320
|
*
|
|
316
321
|
* @exampleMarkdown
|
package/typings/config.d.ts
CHANGED
|
@@ -310,7 +310,12 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
|
|
|
310
310
|
errorHandlingClient: boolean;
|
|
311
311
|
};
|
|
312
312
|
/**
|
|
313
|
-
* @description Controls the enum output type. Options: `string-literal` | `native-numeric` | `const` | `native-const` | `native`;
|
|
313
|
+
* @description Controls the enum output type. Options: `string-literal` | `native-numeric` | `const` | `native-const` | `native` | `native-with-string-values`;
|
|
314
|
+
*
|
|
315
|
+
* `native-with-string-values` declares enums the same way as `native`, and types enums in operation variables and input object fields as ``E | `${E}` ``,
|
|
316
|
+
* so either the enum member or its string value can be passed, e.g. `TargetType.A` or `'A'`.
|
|
317
|
+
* Enums in operation result types stay `E`.
|
|
318
|
+
* Note: if `enumValues` maps an enum's values to numbers, `` `${E}` `` yields their string forms, e.g. `'0' | '1'`.
|
|
314
319
|
* @default `string-literal`
|
|
315
320
|
*
|
|
316
321
|
* @exampleMarkdown
|
|
@@ -6,6 +6,7 @@ export declare class TypeScriptOperationVariablesToObject extends OperationVaria
|
|
|
6
6
|
avoidOptionals: NormalizedOperationAvoidOptionalsConfig;
|
|
7
7
|
immutableTypes: boolean;
|
|
8
8
|
inputMaybeValue: string;
|
|
9
|
+
enumWithStringValues: boolean;
|
|
9
10
|
}, _scalars: NormalizedScalarsMap, _convertName: ConvertNameFn, _namespacedImportName: string | null, _enumNames: string[], _enumPrefix: boolean, _enumSuffix: boolean, _enumValues: ParsedEnumValuesMap, _applyCoercion: boolean);
|
|
10
11
|
protected formatFieldString(fieldName: string, isNonNullType: boolean, hasDefaultValue: boolean): string;
|
|
11
12
|
protected formatTypeString(fieldType: string, _isNonNullType: boolean, _hasDefaultValue: boolean): string;
|
|
@@ -6,6 +6,7 @@ export declare class TypeScriptOperationVariablesToObject extends OperationVaria
|
|
|
6
6
|
avoidOptionals: NormalizedOperationAvoidOptionalsConfig;
|
|
7
7
|
immutableTypes: boolean;
|
|
8
8
|
inputMaybeValue: string;
|
|
9
|
+
enumWithStringValues: boolean;
|
|
9
10
|
}, _scalars: NormalizedScalarsMap, _convertName: ConvertNameFn, _namespacedImportName: string | null, _enumNames: string[], _enumPrefix: boolean, _enumSuffix: boolean, _enumValues: ParsedEnumValuesMap, _applyCoercion: boolean);
|
|
10
11
|
protected formatFieldString(fieldName: string, isNonNullType: boolean, hasDefaultValue: boolean): string;
|
|
11
12
|
protected formatTypeString(fieldType: string, _isNonNullType: boolean, _hasDefaultValue: boolean): string;
|