본문 바로가기

Uber Eats

Uber Eats # 4 entity ObjectType

entity는 데이터베이스 모델이다. 

restaurants 아래 entities를 만들고 restaurant.entity.ts 아래 코드를 작성한다.

import { Field, ObjectType } from "@nestjs/graphql";

@ObjectType()
export class Restaurant {
    @Field(type => String)
    name: string;

    @Field(type => Boolean, {nullable: true})
    isGood?: boolean;
}

resolver를 아래와 같이 변경한다.

import { Query, Resolver } from "@nestjs/graphql";
import { Restaurant } from "./entities/restaurant.entity";

@Resolver(of => Restaurant) // of => Restaurant는 필수가 아니다. 따라서 삭제해도 무방하다.
export class RestaurantsResolver {
    @Query(returns => Restaurant)
    myRestaurant() {
        return true;
    }

}

localhost:3000/graphql 에서 myRestaurant name을 날려보면 에러가 발생한다. 그 이유는 return값이 true이기 때문이다.

'Uber Eats' 카테고리의 다른 글

Uber Eats # 6 validator  (0) 2021.03.06
Uber Eats # 5 Arguments, Mutation  (0) 2021.03.06
Uber Eats # 3 Apollo server  (0) 2021.03.06
Uber Eats # 2 graphql  (0) 2021.03.06
Uber Eats # 1 nest, gitignore, github  (0) 2021.03.06