Which packages are impacted by your issue?
@graphql-codegen/typescript
Describe the bug
When using the enumsAsConst plugin configuration option in graphql-codegen/typescript to generate TypeScript enums for GraphQL enums, the @Deprecated directive is not being added to the generated resolver-types.ts file. This means that any deprecated values in the GraphQL schema are not marked as deprecated in the generated TypeScript types, which could lead to confusion for developers using the generated types.
Your Example Website or App
https://stackblitz.com/edit/github-jbn6g8?file=codegen.ts
Steps to Reproduce the Bug or Issue
- Create a GraphQL schema that includes a deprecated enum value with the
@deprecated directive:
enum Color {
RED
GREEN @deprecated(reason: “Use BLUE instead”)
BLUE
}
- Configure
graphql-codegen with the typescript plugin and the enumsAsConst plugin configuration option:
plugins:
- typescript
config:
enumsAsConst: true
-
Run graphql-codegen to generate TypeScript types for the schema.
-
Inspect the generated resolver-types.ts file and verify that the deprecated enum value does not have the @deprecated JSDoc annotation.
The @deprecated JSDoc annotation is not included in the generated resolver-types.ts file for deprecated enum values when using the enumsAsConst plugin configuration option.
export const Color = {
RED: 'RED',
GREEN: 'GREEN',
BLUE: 'BLUE'
} as const;
Expected behavior
The generated resolver-types.ts file should include the @deprecated JSDoc annotation for any deprecated enum values in the GraphQL schema, even when using the enumsAsConst plugin configuration option.
enum Color {
RED
GREEN @deprecated(reason: "Use BLUE instead")
BLUE
}
export const Color = {
RED: 'RED',
/** @deprecated Use BLUE instead */
GREEN: 'GREEN',
BLUE: 'BLUE'
} as const;
Screenshots or Videos
No response
Platform
- OS: [e.g. macOS, Windows, Linux]
- NodeJS: [e.g. 18.5.0]
graphql version: [e.g. 16.3.0]
@graphql-codegen/* version(s): [e.g. 2.6.2]
Codegen Config File
schema: 'schema.graphql',
documents: 'document.graphql',
generates: {
'types.ts': {
plugins: ['typescript', 'typescript-operations'],
config: { enumsAsConst: true },
},
},
Additional context
No response
Which packages are impacted by your issue?
@graphql-codegen/typescript
Describe the bug
When using the
enumsAsConstplugin configuration option ingraphql-codegen/typescriptto generate TypeScript enums for GraphQL enums, the@Deprecateddirective is not being added to the generatedresolver-types.tsfile. This means that any deprecated values in the GraphQL schema are not marked as deprecated in the generated TypeScript types, which could lead to confusion for developers using the generated types.Your Example Website or App
https://stackblitz.com/edit/github-jbn6g8?file=codegen.ts
Steps to Reproduce the Bug or Issue
@deprecateddirective:graphql-codegenwith thetypescriptplugin and theenumsAsConstplugin configuration option:Run
graphql-codegento generate TypeScript types for the schema.Inspect the generated
resolver-types.tsfile and verify that the deprecated enum value does not have the@deprecatedJSDoc annotation.The
@deprecatedJSDoc annotation is not included in the generatedresolver-types.tsfile for deprecated enum values when using theenumsAsConstplugin configuration option.Expected behavior
The generated
resolver-types.tsfile should include the@deprecatedJSDoc annotation for any deprecated enum values in the GraphQL schema, even when using theenumsAsConstplugin configuration option.Screenshots or Videos
No response
Platform
graphqlversion: [e.g. 16.3.0]@graphql-codegen/*version(s): [e.g. 2.6.2]Codegen Config File
Additional context
No response