전체 글 (117) 썸네일형 리스트형 Uber Eats # 6 validator npm i class-validator, npm i class-transformer를 설치한다. import { ArgsType, Field } from '@nestjs/graphql'; import { IsBoolean, IsString, Length } from 'class-validator'; @ArgsType() export class CreateRestaurantDto { @Field(type => String) @IsString() @Length(5, 10) name: string; @Field(type => Boolean) @IsBoolean() isVegan: boolean; @Field(type => String) @IsString() address: string; @Field(type .. Uber Eats # 5 Arguments, Mutation import { Args, Query, Resolver } from "@nestjs/graphql"; import { Restaurant } from "./entities/restaurant.entity"; @Resolver(of => Restaurant) export class RestaurantsResolver { @Query(returns => [Restaurant]) restaurants(@Args('veganOnly') veganOnly: boolean): Restaurant[] { return []; } } query에 argument를 추가하여 요청할 수 있다. argument에 DTO(Data Transfer Object)를 넣어주어서 요청할 수도 있다. @InputType vs @Args.. 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/restauran.. Uber Eats # 3 Apollo server Apollo server에 원하는 세팅을 보낼 수 있다. typeDefs DocumentNode or Array Required. Document or documents that represent your server's GraphQL schema, generated by applying the gql tag to valid Schema Definition Language (SDL) strings. resolvers Object or Array Required. A map of functions that populate data for individual schema fields. Can also be an array of multiple maps that are merged. 세팅을 하는 방법에는 Co.. Uber Eats # 2 graphql graphql document를 참고해서 설치하기 $ npm i @nestjs/graphql graphql-tools graphql apollo-server-express graphql과 apollo-server-express로 동작 app.module.ts를 제외하고 나머지 삭제(app.controller.spec.ts, app.controller.ts, app.service.ts) app.module은 main.ts에서 import되는 유일한 모듈이다. main.ts는 application을 실행해준다. NestFactory가 AppModule로부터 application을 생성한다. 따라서 AppModule이 데이터베이스를 가져오고 GraphQL 등등을 다 가져온다. GraphQL 모듈을 AppMod.. Uber Eats # 1 nest, gitignore, github Nest를 활용해서 프로젝트 생성하기 nest g application project name: nuber-eats-backend 생성 후 visual studio code에서 npm i를 통해 필요한 패키지 설치 npm run start:dev 명령어 실행 후 localhost:3000 접속하면 Hello World!를 볼 수 있다. github.com에서 Repository 생성하기 프로젝트에서 git init git remote add origin {HTTP} 5000개가 넘는 파일을 커밋해야 하는 상황 gitignore를 통해 필요한 파일만 업로드하기 플로그인 gitignore를 설치하고 command palette를 클릭하고 add gitignore 후 node를 찾아서 엔터를 누른다. 자동으로.. # 3-1 NestJS - 구조 파악하기 @Module 등 데코레이터를 사용한다. 데코레이터는 클래스에 함수 기능을 추가할 수 있다. 클래스 위에 있는 함수라고 생각하면 된다. # 3-0 Nest.js NetsJS는 node.js 위에서 동작하는 프레임워크 백엔드를 쉽게 구성하게 해준다. express 위에서 동작하는 것도 가능 node.js에서는 컨트롤러, 템플릿 등을 원하는대로 작성할 수 있지만 NestJS에서는 정해진 규칙을 따라야 한다. 객체지향 프로그래밍과 함수형 프로그래밍, 함수반응형 프로그래밍 요소를 사용한다. REST API 테스트를 위해서 Insomnia를 설치해야한다. npm i -g @nestjs/cli로 설치하고 nest new를 통해서 프로젝트를 생성한다. github.com/hwan02/hey-nest 이전 1 2 3 4 5 6 ··· 15 다음