dotansimha / dotansimha/graphql-code-generator-community
Enum is being treated as `string` in typescript mongodb plugin
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
**Describe the bug**
Enum is being treated as `string` in typescript mongodb plugin
**To Reproduce**
Steps to reproduce the behavior:
1. Create a simple **@entity** with a **@column** with enum value.
2. Generate the schema with `typescript` & `typescript-mongodb` plugin
## Codesanbox link: [Click here](https://codesandbox.io/s/cocky-fast-h3fyt?file=/schema.graphql)
**My GraphQL schema**:
```graphql
enum Role {
USER
ADMIN
}
type User @entity {
_id: ID! @id
name: String! @column
role: Role! @column
}
```
**My `codegen.yml` config file:**
```yml
schema: ./schema.graphql
config:
enumsAsTypes: true
generates:
./mongodb-types.ts:
plugins:
- typescript-mongodb
- typescript
```
**Expected behavior**
```graphql
export type Maybe = T | null;
export type Exact = { [K in keyof T]: T[K] };
export type MakeOptional = Omit & { [SubKey in K]?: Maybe };
export type MakeMaybe = Omit & { [SubKey in K]: Maybe };
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;
type?: Maybe;
};
```
**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:
```graphql
type User @entity {
name: String! @column
}
```
That will generate
```typescript
export type UserDbObject = {
name: string
};
```
and
```graphql
export type User = {
name: Scalars['String'];
};
```
I only want the upper one output.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.