해결된 질문
작성
·
28
0
entity 등으로 생성된 tpye 에서
강의에서 사용된 코드로 예시를 들면
# product.entity.ts
@JoinTable()
@ManyToMany(() => ProductTag, (productTags) => productTags.products)
@Field(() => [ProductTag], { nullable: true })
productTags: ProductTag[];
위와같이 nullable 을 사용하여
#schema.gql
type Product {
productId: String
productName: String!
description: String!
productPrice: Int!
isSoldout: Boolean!
productSalesLocation: ProductSalesLocation
productCategory: ProductCategory
user: User
productTags: [ProductTag!]
}
productTags: [ProductTag!] 와 같이 할 수 있었습니다.
위에서 productTags: [ProductTag!]
를 productTags: [ProductTag] 와같이 변경 해보려고합니다.
방법이 있나요?
@Field(() => [ProductTag, { nullable: true }], { nullable: true })
에러는 발생하지 않지만 안됩니다.
답변 1
0
안녕하세요! gkdlsb1234님!
이전부터 점점 실력이 많이 늘고 계신게 느껴지네요!^^
nullable을 주는 방법으로 크게 3가지 방법이 있어요!
// 1. nullable: true
@Field(() => [ProductTag], { nullable: true }) // 결과: [ProductTag!]
// 2. nullable: "items"
@Field(() => [ProductTag], { nullable: "items" }) // 결과: [ProductTag]!
// 3. nullable: "itemsAndList"
@Field(() => [ProductTag], { nullable: "itemsAndList" }) // 결과: [ProductTag]
따라서, nullable: "itemsAndList"를 활용해 보시면 좋을 것 같아요!^^