Tunko Development Diary

[NestJS, GraphQL, typeORM]GraphQL Enum Column 생성 본문

Development/Nest.js

[NestJS, GraphQL, typeORM]GraphQL Enum Column 생성

Tunko 2021. 4. 24. 19:53
import {
    Field,
    InputType,
    ObjectType,
    registerEnumType,
} from '@nestjs/graphql';
import { Column, Entity } from 'typeorm';

export enum EXType {
    TYPE1 = 'type1',
    TYPE2 = 'type2'
}

registerEnumType(EXType, { name: 'EXType' });

@ObjectType()
@Entity()
export class EXEntity {
    ...
    @Column({type : 'enum', enum : EXType})
    @Field((type) => EXType) 
    type : EXType
    ...
}

registerEnumType 을 사용하면 GrqphQL 에서 해당 Enum 타입을 인식할 수 있도록 할 수 있다.
Documentation | NestJS - A progressive Node.js framework

반응형
Comments