Here's a well-structured GitHub issue you can log for graphql-codegen-typescript-validation-schema:
Bug Report: enumPrefix and typesPrefix incorrectly applies to enum imports
Description
When using typesPrefix: "I" with importFrom, the generated Zod schemas incorrectly import enums with the I prefix, even though:
- The source TypeScript file (specified in
importFrom) generates enums without the prefix
enumPrefix: false is explicitly set in the configuration
enumsAsTypes: true has been tried as an alternative
This causes a mismatch between the generated types and the Zod schema imports, resulting in TypeScript errors.
Expected Behavior
When typesPrefix: "I" is set:
- Interfaces/types should be imported as
IMyType
- Enums should be imported as
MyEnum (without the I prefix)
The enumPrefix: false configuration should prevent the prefix from being applied to enum imports.
Current Behavior
Enums are incorrectly imported with the I prefix:
// Generated Zod file
import type { IMyEnum } from './generated-models'; // ❌ Wrong
// But the actual generated-models file has:
export enum MyEnum { ... } // Without 'I' prefix
This causes TypeScript error:
Module '"./generated-models"' has no exported member 'IMyEnum'
Configuration
generates:
./src/generated/graphql-types.ts:
plugins:
- typescript
config:
typesPrefix: I
enumsAsTypes: false
./src/generated/graphql-zod.ts:
plugins:
- typescript-validation-schema
config:
schema: zod
importFrom: ./graphql-types
typesPrefix: I
enumPrefix: false # ❌ Not working
enumsAsTypes: true # ❌ Also tried this, doesn't help
withObjectType: false
notAllowEmptyString: true
useTypeImports: true
scalarSchemas:
DateTime: z.string().datetime()
Date: z.string().date()
JSON: z.record(z.unknown())
GraphQL Schema
enum UserRole {
ADMIN
USER
GUEST
}
input CreateUserInput {
name: String!
role: UserRole!
}
Generated TypeScript Types (graphql-types.ts)
// ✅ Enum generated WITHOUT prefix (correct)
export enum UserRole {
Admin = 'ADMIN',
User = 'USER',
Guest = 'GUEST'
}
// ✅ Interface generated WITH prefix (correct)
export interface ICreateUserInput {
name: string;
role: UserRole;
}
Generated Zod Schema (graphql-zod.ts)
import { z } from 'zod';
import type { IUserRole } from './graphql-types'; // ❌ Wrong! Should be UserRole
import type { ICreateUserInput } from './graphql-types'; // ✅ Correct
export const CreateUserInputSchema = z.object({
name: z.string(),
role: z.nativeEnum(IUserRole) // ❌ TypeScript error: IUserRole doesn't exist
});
Expected Generated Zod Schema
import { z } from 'zod';
import type { UserRole } from './graphql-types'; // ✅ Correct - no prefix
import type { ICreateUserInput } from './graphql-types'; // ✅ Correct - with prefix
export const CreateUserInputSchema = z.object({
name: z.string(),
role: z.nativeEnum(UserRole) // ✅ Works correctly
});
Environment
graphql-codegen-typescript-validation-schema version: [INSERT YOUR VERSION]
@graphql-codegen/cli version: [INSERT YOUR VERSION]
@graphql-codegen/typescript version: [INSERT YOUR VERSION]
- Node version: [INSERT YOUR VERSION]
- Package manager: npm/yarn/pnpm
Reproduction
- Configure codegen with
typesPrefix: "I" in the typescript plugin
- Configure
typescript-validation-schema with importFrom pointing to the types file
- Set
enumPrefix: false or enumsAsTypes: true
- Generate code
- Observe that enum imports have the
I prefix in the Zod file
Workarounds Attempted
- ✅ Tried: Setting
enumPrefix: false - Doesn't work
- ✅ Tried: Setting
enumsAsTypes: true - Doesn't work
- ✅ Tried: Setting both together - Doesn't work
- ⚠️ Current workaround: Manually find/replace enum imports after generation
Proposed Solution
The typescript-validation-schema plugin should respect the enumPrefix configuration or provide a separate configuration option like enumImportPrefix that defaults to false when enumPrefix: false is set.
Alternatively, the plugin could:
- Check if the imported type is an enum
- Apply
typesPrefix only to non-enum types
- Or provide a
skipPrefixForEnums option
Additional Context
This issue makes it difficult to use a consistent naming convention where:
- Interfaces have prefixes (e.g.,
IUser)
- Enums don't have prefixes (e.g.,
UserRole)
This is a common TypeScript convention and the @graphql-codegen/typescript plugin supports it correctly with enumPrefix: false, but typescript-validation-schema doesn't respect this setting when importing.
Related Issues
- Similar to how
typesPrefix works in @graphql-codegen/typescript
- May be related to how imports are generated in the plugin
Here's a well-structured GitHub issue you can log for
graphql-codegen-typescript-validation-schema:Bug Report:
enumPrefixandtypesPrefixincorrectly applies to enum importsDescription
When using
typesPrefix: "I"withimportFrom, the generated Zod schemas incorrectly import enums with theIprefix, even though:importFrom) generates enums without the prefixenumPrefix: falseis explicitly set in the configurationenumsAsTypes: truehas been tried as an alternativeThis causes a mismatch between the generated types and the Zod schema imports, resulting in TypeScript errors.
Expected Behavior
When
typesPrefix: "I"is set:IMyTypeMyEnum(without theIprefix)The
enumPrefix: falseconfiguration should prevent the prefix from being applied to enum imports.Current Behavior
Enums are incorrectly imported with the
Iprefix:This causes TypeScript error:
Configuration
GraphQL Schema
Generated TypeScript Types (
graphql-types.ts)Generated Zod Schema (
graphql-zod.ts)Expected Generated Zod Schema
Environment
graphql-codegen-typescript-validation-schemaversion: [INSERT YOUR VERSION]@graphql-codegen/cliversion: [INSERT YOUR VERSION]@graphql-codegen/typescriptversion: [INSERT YOUR VERSION]Reproduction
typesPrefix: "I"in thetypescriptplugintypescript-validation-schemawithimportFrompointing to the types fileenumPrefix: falseorenumsAsTypes: trueIprefix in the Zod fileWorkarounds Attempted
enumPrefix: false- Doesn't workenumsAsTypes: true- Doesn't workProposed Solution
The
typescript-validation-schemaplugin should respect theenumPrefixconfiguration or provide a separate configuration option likeenumImportPrefixthat defaults tofalsewhenenumPrefix: falseis set.Alternatively, the plugin could:
typesPrefixonly to non-enum typesskipPrefixForEnumsoptionAdditional Context
This issue makes it difficult to use a consistent naming convention where:
IUser)UserRole)This is a common TypeScript convention and the
@graphql-codegen/typescriptplugin supports it correctly withenumPrefix: false, buttypescript-validation-schemadoesn't respect this setting when importing.Related Issues
typesPrefixworks in@graphql-codegen/typescript