Skip to content

Commit 5ca8d00

Browse files
committed
add useTypeImports config
1 parent f67ff70 commit 5ca8d00

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/config.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ export interface ValidationSchemaPluginConfig extends TypeScriptPluginConfig {
5252
* ```
5353
*/
5454
importFrom?: string;
55+
/**
56+
* @description Will use `import type {}` rather than `import {}` when importing generated typescript types.
57+
* This gives compatibility with TypeScript's "importsNotUsedAsValues": "error" option
58+
* Should used in conjunction with `importFrom` option.
59+
*
60+
* @exampleMarkdown
61+
* ```yml
62+
* generates:
63+
* path/to/types.ts:
64+
* plugins:
65+
* - typescript
66+
* path/to/schemas.ts:
67+
* plugins:
68+
* - graphql-codegen-validation-schema
69+
* config:
70+
* schema: yup
71+
* importFrom: ./path/to/types
72+
* useTypeImports: true
73+
*
74+
* ```
75+
*/
76+
useTypeImports?: boolean;
5577
/**
5678
* @description Prefixes all import types from generated typescript type.
5779
* @default ""

src/myzod/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export const MyZodSchemaVisitor = (schema: GraphQLSchema, config: ValidationSche
2525
return {
2626
buildImports: (): string[] => {
2727
if (config.importFrom && importTypes.length > 0) {
28-
return [importZod, `import { ${importTypes.join(', ')} } from '${config.importFrom}'`];
28+
return [
29+
importZod,
30+
`import ${config.useTypeImports ? 'type ' : ''}{ ${importTypes.join(', ')} } from '${config.importFrom}'`,
31+
];
2932
}
3033
return [importZod];
3134
},

0 commit comments

Comments
 (0)