Type-graphql: Schema fails to be generated when using an EnumType

Created on 12 Mar 2020  路  3Comments  路  Source: MichalLytek/type-graphql

Describe the bug
The schema fails to be generated when using an EnumType

To Reproduce

export enum UserRole {
  ADMIN = "ADMIN",
  EDITOR = "EDITOR",
  GHOST = "GHOST"
}
registerEnumType(UserRole, {
  name: "User Role",
  description: "User role types"
});

@Entity("users")
@ObjectType()
export class User extends BaseEntity {
  @Field((type) => UserRole, {
    description: "User's role (share role options)"
  })
  @Column({
    type: "enum",
    enum: UserRole,
    default: UserRole.GHOST
  })
  role: UserRole;
}

When I comment the part that sets the field type to that of the enum (as shown below) it runs fine.

  // @Field((type) => UserRole, {
  //   description: "User's role (share role options)"
  // })
  @Column({
    type: "enum",
    enum: UserRole,
    default: UserRole.GHOST
  })
  role: UserRole;

Also, if I swap UserRole to a String type it works fine.

  @Field((type) => String, {
    description: "User's role (share role options)"
  })

Expected behavior
The schema should be generated.

Logs
(node:51343) UnhandledPromiseRejectionWarning: Error: Generating schema error
at Function. (/project-path/node_modules/type-graphql/dist/schema/schema-generator.js:20:27)
at Generator.next ()
at fulfilled (/project-path/node_modules/tslib/tslib.js:110:62)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:51343) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:51343) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[nodemon] clean exit - waiting for changes before restart

Enviorment (please complete the following information):

  • OS: MacOS (10.15.3 - Catalina )
  • Node (13.7.0 )
  • Package version (^0.17.6 )
  • TypeScript version (^3.8.2 )

Additional context
Add any other context about the problem here.

Question Solved

Most helpful comment

registerEnumType(UserRole, {
  name: "User Role",
  description: "User role types"
});

Thinking the space in "User Role" is a problem.

All 3 comments

1) Fill the template properly because latest is not precise at all.

2) Capture the error and print the details property of that GeneratingSchemaError.

registerEnumType(UserRole, {
  name: "User Role",
  description: "User role types"
});

Thinking the space in "User Role" is a problem.

@wickning1
That's solved it actually. Thanks so much.
Can't believe I missed that.

Thanks again!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

avkonst picture avkonst  路  3Comments

maplesteve picture maplesteve  路  3Comments

limenutt picture limenutt  路  3Comments

MichalLytek picture MichalLytek  路  3Comments

laukaichung picture laukaichung  路  3Comments