enum UserRole { Owner, // 0 Client, // 1 Delevery, // 2 }
enum의 값에는 자동으로 0부터 증가하는 값이 부여된다.
다른 값을 부여하고 싶다면 명시적으로 넣어주면 된다.
with typeOrm
export class User extends CoreEntity { ... @Column({ type: 'enum', enum: UserRole, }) @Field((type) => String) role: UserRole; }
typeorm
을 사용하고 있다면 @Column
을 사용할 때 해당 값이 enum이라면type: ‘enum’
이라고 명시해줘야 한다.
- 구체적으로 어떤 enum 인지까지
enum: <Enum명>
으로 명시해줘야 한다.
with graphql
registerEnumType(UserRole, { name: 'UserRole' });
typescript로 작성한 enum을
graphql
에서도 사용할 수 있다.registerEnumType
을 통해 enum을 graphql schema
에도 등록할 수 있고, 등록하고자 하는 이름을 다르게 하는 등 상세 옵션도 있다.