Decorators

    유저 프로필 수정 시 Mapped types 주의할 점

    유저 프로필 수정 시 Mapped types 주의할 점

    // 잘못된 예export class EditProfileInput extends PickType(User, ["email", "password"]) {}// 올바른 예export class EditProfileInput extends PartialType( PickType(User, ["email", "password"]),) {}유저의 이메일과 패스워드를 사용할 것이기 때문에 PickType을 사용할 수 있지만프로필 수정하는 것이기 때문에 이메일과 패스워드는 수정될 수 있다!즉 이메일만 수정, 또는 패스워드만 수정하는 경우가 있다.PickType이 아닌 PartialType에서 PickType을 사용하자user에서 email, password를 가지고 class를 만들고PartialType을 사용해..

    GraphQL 스키마를 정의할 때 사용되는 데코레이터

    GraphQL 스키마를 정의할 때 사용되는 데코레이터

    @InputType()GraphQL에서 입력 객체를 정의할 때 사용주로 mutation에서 사용되는 인자로, 여러 필드를 하나의 입력 객체로 그룹화하여 사용할 수 있다.예를 들어, 사용자를 생성하는 mutation에서 여러 필드를 하나의 입력 타입으로 묶어 처리할 수 있다.import { InputType, Field } from '@nestjs/graphql';@InputType()class CreateUserInput { @Field() username: string; @Field() password: string; @Field() email: string;}import { Resolver, Mutation, Args } from '@nestjs/graphql';@Resolver()clas..

    InputTypes and ArgumentTypes

    InputTypes and ArgumentTypes

    Mutation 추가restaurants/restaurants.resolver.tsimport { Args, Mutation, Query, Resolver } from "@nestjs/graphql";import { Restaurant } from "./entities/restaurants.entity";@Resolver(() => Restaurant)export class RestaurantsResolver { @Query(() => [Restaurant]) restaurants(@Args("veganOnly") veganOnly: boolean): Restaurant[] { return []; } @Mutation(() => Boolean) createRestaurant(): boole..

    type-graphql의 isAbstract 옵션

    type-graphql의 isAbstract 옵션

    { isAbstract: true }type-graphql 라이브러리에서 제공하는 옵션이다.해당 클래스가 GraphQL 스키마에 직접적으로 매핑되지 않고, 추상적인 타입으로만 사용될 수 있음을 나타낸다.즉, 스키마에서는 실제 타입으로 정의되지 않고, 다른 클래스에서 확장이나 참조할 수 있는 추상적인 역할을 수행할 수 있다.일반적으로 @InputType() 또는 @ObjectType() 데코레이터를 사용할 때, isAbstract: true 옵션을 함께 사용하면 클래스가 실제 GraphQL 스키마에 등록되는 것을 방지할 수 있다.이는 스키마에서 중복된 이름의 타입이 생성되는 것을 방지하고, 클래스를 추상적인 개념으로만 유지할 수 있도록 도와준다.