import { EnumTypeDefinitionNode, EnumTypeExtensionNode, GraphQLEnumType, } from 'graphql'; import { Maybe } from 'graphql/jsutils/Maybe'; interface GraphqlEnumTypeConfig { name: string; description?: Maybe; values: T; extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } export const enumToGraphqlEnum = (values: T) => Object.keys(values) .filter((value) => isNaN(Number(value)) === false) .reduce((acc, value) => { acc[(values as unknown)[value]] = { value: Number(value) }; return acc; }, {} as T); export class GraphqlEnumType extends GraphQLEnumType { constructor(config: GraphqlEnumTypeConfig) { config.values = enumToGraphqlEnum(config.values); super(config as never); } }