Frontend/Nest.js

    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 스키마에 등록되는 것을 방지할 수 있다.이는 스키마에서 중복된 이름의 타입이 생성되는 것을 방지하고, 클래스를 추상적인 개념으로만 유지할 수 있도록 도와준다.

    @InputType과 @ObjectType을 동시에 데코레이터 사용 시 주의할 점

    @InputType과 @ObjectType을 동시에 데코레이터 사용 시 주의할 점

    import { InputType, ObjectType } from 'type-graphql';@InputType()@ObjectType()class Episode { // class fields and methods}위 코드에 Episode 클래스는 동시에 @InputType()과 @ObjectType() 데코레이터가 적용되어 있다.이 경우, 자동으로 생성되는 SDL(Schema Definition Language)에서 이름 충돌이 발생할 수 있다.  type Episode { # fields defined by @ObjectType()}input Episode { # fields defined by @InputType()}SDL로 변환하면 자동으로 클래스 이름으로 type 또는 input 등의 ..

    NestJS : DTO 데이터 전송 객체 (Data Transfer Object)

    NestJS : DTO 데이터 전송 객체 (Data Transfer Object)

    DTO 장점 DTO는 타입이 애플리케이션이 움직일 때 도움을 준다. 코드를 간결하게 만들어 준다. NestJS 가 들어오는 쿼리에 대해 유효성을 검사할 수 있게 해 준다. DTO 만 작성 시 유효성을 검사해주진 않는다. (유효성 검사용 파이프 만들기) 메인에 유효성 검사용 파이프 만들기 파이프란? 코드가 지나가는 곳 미들웨어 같은 것이라 생각할 수 있다. 파이프 적용 src/main.ts import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { ValidationPipe } from '@nestjs/common/pipes'; async function bootstrap() { const app..