dotansimha/graphql-code-generator-community
在 GitHub 查看Enum is being treated as `string` in typescript mongodb plugin
Open
#134 创建于 2021年6月26日
help wanted
仓库指标
- Star
- (136 star)
- PR 合并指标
- (PR 指标待抓取)
描述
Describe the bug
Enum is being treated as string in typescript mongodb plugin
To Reproduce
Steps to reproduce the behavior:
- Create a simple @entity with a @column with enum value.
- Generate the schema with
typescript&typescript-mongodbplugin
Codesanbox link: Click here
My GraphQL schema:
enum Role {
USER
ADMIN
}
type User @entity {
_id: ID! @id
name: String! @column
role: Role! @column
}
My codegen.yml config file:
schema: ./schema.graphql
config:
enumsAsTypes: true
generates:
./mongodb-types.ts:
plugins:
- typescript-mongodb
- typescript
Expected behavior
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
import { ObjectID } from 'mongodb';
export type UserDbObject = {
_id: ObjectID,
name: string,
role: string, /*********** EXPECTED THIS TYPE TO BE ```Role``` TYPE *******/
};
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
};
export type Role =
| 'USER'
| 'ADMIN';
export type User = {
__typename?: 'User';
_id: Scalars['ID'];
name: Scalars['String'];
role: Role;
};
export type AdditionalEntityFields = {
path?: Maybe<Scalars['String']>;
type?: Maybe<Scalars['String']>;
};
Environment:
- OS: Windows 10 64 bit
@graphql-codegen/cli: 1.20.1@graphql-codegen/typescript: 1.21.0@graphql-codegen/typescript-mongodb: 1.19.3- NodeJS: 14.16.1
Additional context
I have tried only using typescript-mongodb plugin it doesn't even generate enums but when I use typescript plugin extra types are generated which is also I don't want for example:
type User @entity {
name: String! @column
}
That will generate
export type UserDbObject = {
name: string
};
and
export type User = {
name: Scalars['String'];
};
I only want the upper one output.