Skip to content

Commit 85c99b2

Browse files
committed
Simplify enumType config
1 parent 5fb5c34 commit 85c99b2

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

packages/plugins/typescript/operations/src/config.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
337337
errorHandlingClient: boolean;
338338
};
339339

340-
enumType?:
341-
| { type: 'string-literal' }
342-
| { type: 'numeric-enums' }
343-
| { type: 'as-const' }
344-
| { type: 'native-const' }
345-
| { type: 'native' };
340+
enumType?: 'string-literal' | 'numeric' | 'const' | 'native-const' | 'native';
346341
enumValues?: EnumValuesMap;
347342
futureProofEnums?: boolean;
348343
}

packages/plugins/typescript/operations/src/visitor.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ export interface TypeScriptDocumentsParsedConfig extends ParsedDocumentsConfig {
4646
noExport: boolean;
4747
maybeValue: string;
4848
allowUndefinedQueryVariables: boolean;
49-
enumType:
50-
| { type: 'string-literal' }
51-
| { type: 'numeric-enums' }
52-
| { type: 'as-const' }
53-
| { type: 'native-const' }
54-
| { type: 'native' };
49+
enumType: 'string-literal' | 'numeric' | 'const' | 'native-const' | 'native';
5550
futureProofEnums: boolean;
5651
enumValues: ParsedEnumValuesMap;
5752
}
@@ -75,7 +70,7 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
7570
preResolveTypes: getConfigValue(config.preResolveTypes, true),
7671
mergeFragmentTypes: getConfigValue(config.mergeFragmentTypes, false),
7772
allowUndefinedQueryVariables: getConfigValue(config.allowUndefinedQueryVariables, false),
78-
enumType: getConfigValue(config.enumType, { type: 'string-literal' }),
73+
enumType: getConfigValue(config.enumType, 'string-literal'),
7974
enumValues: parseEnumValues({
8075
schema,
8176
mapOrStr: config.enumValues,
@@ -208,7 +203,17 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
208203
this.config.futureProofEnums ? [indent('| ' + wrapWithSingleQuotes('%future added value'))] : [],
209204
];
210205

211-
if (this.config.enumType.type === 'string-literal') {
206+
// handle:
207+
// - enumValues x
208+
// - future added values
209+
210+
// - ✅ enumsAsTypes
211+
// - numericEnums
212+
// - enumsAsConst
213+
// - native const enum
214+
// - native enum
215+
216+
if (this.config.enumType === 'string-literal') {
212217
return new DeclarationBlock(this._declarationBlockConfig)
213218
.asKind('type')
214219
.withComment(node.description?.value)
@@ -228,16 +233,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
228233
).string;
229234
}
230235

231-
// handle:
232-
// - enumValues x
233-
// - future added values
234-
235-
// - enumsAsTypes
236-
// - numericEnums
237-
// - enumsAsConst
238-
// - native const enum
239-
// - native enum
240-
241236
return 'FOUND ';
242237
}
243238

0 commit comments

Comments
 (0)