[Nest.js] ์ดˆ๊ธฐ ํ™˜๊ฒฝ ๊ตฌ์„ฑ (feat. TypeORM, QueryBuilder, GraphQL, Apollo)

2023. 12. 5. 00:44ใ†Back-End ์ž‘์—…์‹ค/Nest.js

728x90
๋ฐ˜์‘ํ˜•

 

 

์นด์นด์˜คํŽ˜์ด | ๋งˆ์Œ ๋†“๊ณ  ๊ธˆ์œตํ•˜๋‹ค

์—ฌ๊ธฐ๋ฅผ ๋ˆŒ๋Ÿฌ ๋งํฌ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

qr.kakaopay.com

 

 

 

์ž๋ฐ” ORM ํ‘œ์ค€ JPA ํ”„๋กœ๊ทธ๋ž˜๋ฐ:์Šคํ”„๋ง ๋ฐ์ดํ„ฐ ์˜ˆ์ œ ํ”„๋กœ์ ํŠธ๋กœ ๋ฐฐ์šฐ๋Š” ์ „์ž์ •๋ถ€ ํ‘œ์ค€ ๋ฐ์ดํ„ฐ๋ฒ ์ด

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 




๐Ÿ—‚ ๋ชฉ์ฐจ

โœ… GraphQL๊ณผ Apollo ์ฒซ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - ๊ฐœ๋… ์ตํžˆ๊ธฐ
โœ… GraphQL๊ณผ Apollo ๋‘๋ฒˆ์งธ ์ด์•ผ๊ธฐ - REST API๋ž€?
โœ… GraphQL๊ณผ Apollo ์„ธ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - GraphQL์˜ ์ •๋ณด ์ฃผ๊ณ  ๋ฐ›๋Š” ๋ฐฉ์‹

โœ… GraphQL๊ณผ Apollo ๋„ค๋ฒˆ์งธ ์ด์•ผ๊ธฐ - Apollo๋ž€?
โœ… GraphQL๊ณผ Apollo ๋‹ค์„ฏ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - GraphQL์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด ๋ณด์•„์š” ๐Ÿ˜€
โœ… GraphQL๊ณผ Apollo ์—ฌ์„ฏ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - GraphQL Moduleํ™”์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•„์š” ๐Ÿ˜€
โœ… GraphQL๊ณผ Apollo ์ผ๊ณฑ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - GraphQL Data Type์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•„์š” ๐Ÿ˜€
โœ… GraphQL๊ณผ Apollo ์—ฌ๋Ÿ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - GraphQL Union๊ณผ Interface ๊ทธ๋ฆฌ๊ณ  ์ธ์ž์™€ ์ธํ’‹ ํƒ€์ž…์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์•„์š” ๐Ÿ˜€
โœ… GraphQL๊ณผ Apollo ์•„ํ™‰๋ฒˆ์งธ ์ด์•ผ๊ธฐ - Java + Spring Boot์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ™˜๊ฒฝ ๊ตฌ์„ฑ
โœ… GraphQL๊ณผ Apollo ์—ด๋ฒˆ์งธ ์ด์•ผ๊ธฐ - Java + Spring Boot์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ•ด๋ณด๊ธฐ
โœ… GraphQL๊ณผ Apollo ์—ด ํ•œ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - TypeScript + Nest.js์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ™˜๊ฒฝ ๊ตฌ์„ฑ
โœ… 
GraphQL๊ณผ Apollo ์—ด ๋‘๋ฒˆ์งธ ์ด์•ผ๊ธฐ - TypeScript + Nest.js์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ™˜๊ฒฝ ํ…Œ์ŠคํŠธ
โœ… GraphQL๊ณผ Apollo ์—ด ์„ธ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - TypeScript + Nest์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ•ด๋ณด๊ธฐ
โœ… 
GraphQL๊ณผ Apollo ์—ด ๋„ค๋ฒˆ์งธ ์ด์•ผ๊ธฐ - React์™€ Apollo Client
โœ… GraphQL๊ณผ Apollo ์—ด๋‹ค์„ฏ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - React์™€ Apollo Client - Query์™€ Mutation ์‚ฌ์šฉํ•˜์—ฌ ์›น ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ
โœ… GraphQL๊ณผ Apollo ์—ด ์—ฌ์„ฏ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - Kotlin + Spring Boot์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ™˜๊ฒฝ ๊ตฌ์„ฑ
โœ… GraphQL๊ณผ Apollo ์—ด ์ผ๊ณฑ๋ฒˆ์งธ ์ด์•ผ๊ธฐ - Kotlin + Spring Boot์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ•ด๋ณด๊ธฐ


๐Ÿค” ๋‚ด๊ฐ€ ๋งŒ๋‚œ ๋ฌธ์ œ

โš ๏ธ [Nest.js] TypeORM Table ๊ด€๊ณ„๊ฐ€ ๋งบ์–ด์กŒ์„ ๋•Œ, Seeding (feat. Migration)
โš ๏ธ [Spring Boot 3.0] Could not resolve org.springframework.boot:spring-boot-gradle-plugin
โš ๏ธ [Spring Boot 3] Spring Doc(Swagger) White Label Error


๐Ÿ“‹ ๋ถ€๋ก

๐Ÿ” [Nest.js] ์ดˆ๊ธฐ ํ™˜๊ฒฝ ๊ตฌ์„ฑ (feat. TypeORM, QueryBuilder, GraphQL, Apollo)
๐Ÿ” [SOLID][Nest.js][Java + Spring] Interface๋ฅผ ํ™œ์šฉํ•œ ๊ฒฐํ•ฉ๋„ ๋ถ„๋ฆฌ (Interface๋ฅผ ์ด์šฉํ•œ Dependency Injection - DI)

 

 

 

 

GitHub - junyharang-coding-study/GraphQL-Study: GraphQL์„ ๊ณต๋ถ€ํ•˜๊ณ , ์‹ค์Šตํ•œ ์ฝ”๋“œ์—์š” ๐Ÿ˜€

GraphQL์„ ๊ณต๋ถ€ํ•˜๊ณ , ์‹ค์Šตํ•œ ์ฝ”๋“œ์—์š” ๐Ÿ˜€. Contribute to junyharang-coding-study/GraphQL-Study development by creating an account on GitHub.

github.com

 

 

 

 

๐Ÿš€ [Nest.js] ์ดˆ๊ธฐ ํ™˜๊ฒฝ ๊ตฌ์„ฑ

    ๐Ÿ”ฝ ํ™˜๊ฒฝ ๊ตฌ์„ฑ

        ๐Ÿ“ฆ ์‹ค์Šต ํ™˜๊ฒฝ 

๐Ÿ” MacOS (M1 MacBook Pro Sonoma 14.1.1)
๐Ÿ” TypeScript

๐Ÿ” Nest.js
๐Ÿ” Embedded SQLite DBMS
๐Ÿ” TypeORM 0.3.17
๐Ÿ” InteliJ (2023.2.5 Ultimate)

 

 

 

 

        ๐Ÿ“ฆ ์ดˆ๊ธฐ ๊ตฌ์„ฑ

์ตœ์ดˆ Project(ํ”„๋กœ์ ํŠธ)๋ฅผ ๋‹ด์„ Directory(๋””๋ ‰ํ„ฐ๋ฆฌ)๋ฅผ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.

mkdir <๋””๋ ‰ํ„ฐ๋ฆฌ ์ด๋ฆ„>


์œ„์™€ ๊ฐ™์ด Terminal์„ ์ด์šฉํ•ด์„œ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.


InteliJ -> File -> Open


๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ InteliJ(์ธํ…”๋ฆฌ์ œ์ด)๋กœ ์—ด์–ด ์ฃผ์—ˆ์–ด์š”.


 

npm i -g @nestjs/cli


์œ„์™€ ๊ฐ™์ด Nest CLI(Command Line Interface)๋ฅผ ์ „์—ญ์ ์œผ๋กœ ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.
์ด๋ฅผ ์ด์šฉํ•˜๋ฉด Nest.js Application(์• ํ”Œ๋ฆฌ์ผ€์ด์…˜)์„ ์ดˆ๊ธฐํ™”ํ•˜๊ณ , Controller(์ปจํŠธ๋กค๋Ÿฌ), Server(์„œ๋น„์Šค - ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง), Module(๋ชจ๋“ˆ) ๋“ฑ์˜ ๊ตฌ์กฐ๋ฅผ ์‰ฝ๊ฒŒ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ , ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ Build(๋นŒ๋“œ)ํ•˜๊ณ , ์‹คํ–‰ํ•˜๋Š” ๋“ฑ์˜ ์ž‘์—…์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ์นœ๊ตฌ์—์š”.

์ด๋ ‡๊ฒŒ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ํ„ฐ๋ฏธ๋„์—์„œ nest ๊ด€๋ จ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋˜๊ณ ,
nest new ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด ์ƒˆ๋กœ์šด Nest.js ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์–ด์š”.


nest new <ํ”„๋กœ์ ํŠธ ์ด๋ฆ„>


์œ„์™€ ๊ฐ™์ด Nest.js ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ ๋ช…์‹œํ•˜์—ฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด ์ค„ ์ˆ˜ ์žˆ์–ด์š”.

์ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด Which package manager would you โค๏ธ to use? ๋ผ๋Š”
์งˆ๋ฌธ์ด ๋‚˜์˜ค๋ฉด์„œ ์„ ํƒ์ง€๋กœ npm, yarn, pnpm ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•˜๊ฒŒ ๋ ํ…๋ฐ,
์ฃผ๋‹ˆ๋Š” Package Manager(ํŒจํ‚ค์ง€ ๋งค๋‹ˆ์ ธ)๋กœ npm์„ ์‚ฌ์šฉํ•˜๋„๋ก ์„ ํƒํ•˜์˜€์–ด์š”.



์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์„ค์น˜ํ•ด์ค˜์„œ ๊ณ ๋ง™๋‹ค๊ณ  ๋‚˜์˜ฌ๊ฑฐ์—์š”.



๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด ๊ธฐ๋ณธ์ ์œผ๋กœ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€๋“ค์ด ์„ค์น˜๋œ ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.


tsconfig.json ์ˆ˜์ • ์ „

 

tsconfig.json ์ˆ˜์ • ํ›„

 "esModuleInterop": true


์ด๊ฒƒ์€ TypeScript Compiler(์ปดํŒŒ์ผ๋Ÿฌ) Option(์˜ต์…˜) ์ค‘ ํ•˜๋‚˜๋กœ ECMAScript ๋ชจ๋“ˆ ๊ฐ„์˜ ์ƒํ˜ธ ์šด์šฉ์„ฑ(Interoperability)๋ฅผ ํ–ฅ์ƒ์‹œํ‚ค๋Š”๋ฐ, ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด์—์š”.

์ด๋ ‡๊ฒŒ ์˜ต์…˜์„ ํ™œ์„ฑํ™” ํ•˜๋ฉด CommonJS ๋ฐ ES6 Style(์Šคํƒ€์ผ) ๋ชจ๋“ˆ๊ฐ„์˜ ์ฐจ์ด๋ฅผ ์กฐ๊ธˆ ๋” ํŽธ๋ฆฌํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ TypeScript๋Š” CommonJS ์Šคํƒ€์ผ์˜ ๋ชจ๋“ˆ System(์‹œ์Šคํ…œ)๊ณผ
ES6 ์Šคํƒ€์ผ์˜ ๋ชจ๋“ˆ ์‹œ์Šคํ…œ ๊ฐ„ ์•ฝ๊ฐ„์˜ ์ฐจ์ด๊ฐ€ ์žˆ์–ด์š”.
์ด๊ฒƒ์„ ํ™œ์„ฑํ™”ํ•˜๊ฒŒ ๋˜๋ฉด ์ด๋Ÿฌํ•œ ์ฐจ์ด๋ฅผ ๋ณด๋‹ค ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜๋„ ์žˆ๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๋ช…ํ•ด ๋ณด์ž๋ฉด
import * as fs from 'fs'; ๋Œ€์‹  import fs from 'fs'; ์™€ ๊ฐ™์ด import ๋ฌธ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.
๋˜ํ•œ, CommonJS ์Šคํƒ€์ผ์˜ ๋ชจ๋“ˆ์—์„œ๋„ export defafult ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“ˆ์„ ๋‚ด๋ณด๋‚ผ ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.
์ผ๋ฐ˜์ ์œผ๋กœ ์ด ์˜ต์…˜์„ ํ™œ์„ฑํ™” ํ•˜๋Š”๊ฑธ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ๋‹ค๊ณ  ํ•ด์š”.


main.ts (์ˆ˜์ • ์ „)

 

main.ts (์ˆ˜์ • ํ›„)


์œ„ ์„ค์ •์€ ์„œ๋ฒ„ ๊ตฌ๋™ Port ๋ฒˆํ˜ธ๋ฅผ ๋ณด๋‹ค ํŽธ๋ฆฌํ•˜๊ฒŒ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์„ค์ •ํ•ด ์ค€ ๋ถ€๋ถ„์ด์—์š”.
ํ•ด๋‹น ์„œ๋ฒ„๋Š” 8081 Port๋กœ ๊ตฌ๋™๋ ๊ฑฐ๊ณ , ๊ตฌ๋™์ด ๋˜๋ฉด 10๋ฒˆ์งธ ๋ฌธ์ž์—ด์ด ์ถœ๋ ฅ๋ ๊ฑฐ์—์š”.


.prettierrc (์ˆ˜์ • ์ „)



.prettierrc (์ˆ˜์ • ํ›„)


.prettierrc๋Š” Code Formmater(์ฝ”๋“œ ํฌ๋งคํ„ฐ) Prettier์˜ ์„ค์ • ํŒŒ์ผ์ด์—์š”.
์ด๊ฑธ ์ด์šฉํ•ด์„œ Code(์ฝ”๋“œ) ์Šคํƒ€์ผ์„ ์–ด๋–ค์‹์œผ๋กœ ๊ตฌํ˜„ํ• ์ง€๋ฅผ ์ •์˜ํ•ด ๋‘˜ ์ˆ˜ ์žˆ์–ด์š”.

์ด๋ฅผ ํ†ตํ•ด ํ˜‘์—…ํ•  ๋•Œ, ์ฝ”๋“œ ์Šคํƒ€์ผ์„ ์ผ๊ด€์„ฑ ์žˆ๊ฒŒ ์œ ์ง€ํ•˜๊ณ , ๊ฐ€๋…์„ฑ์„ ๋†’์—ฌ ์ค„ ์ˆ˜ ์žˆ์–ด์š”.

์ข…    ๋ฅ˜ ์ƒ ์„ธ ๋‚ด ์šฉ
printWidth: 150 ํ•œ ์ค„์— ์ถœ๋ ฅํ•  ์ตœ๋Œ€ ๋ฌธ์ž ์ˆ˜ ์ง€์ •.
150์œผ๋กœ ์„ค์ • ์‹œ ํ•œ ์ค„์— 150์ž ๋„˜๊ฒŒ ๋ฌธ์ž๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ ์ค„ ๋ฐ”๊ฟˆ ์ˆ˜ํ–‰.
tabwidth: 2 Tab ๋ฌธ์ž ํฌ๊ธฐ ์ง€์ •.
2๋กœ ์„ค์ • ์‹œ ํ•œ ๊ฐœ์˜ Tab์— 2๊ฐœ์˜ ๊ณต๋ฐฑ ์‚ฌ์šฉ.
singleQuote: true ๋ฌธ์ž์—ด์„ ์ž‘์€ ๋”ฐ์˜ดํ‘œ๋กœ ํ‘œ๊ธฐํ• ์ง€ ์—ฌ๋ถ€ ์„ค์ •.
trailingComma: all ๊ฐ์ฒด๋‚˜ ๋ฐฐ์—ด์˜ ๋งˆ์ง€๋ง‰ ์š”์†Œ ๋’ค์— ํ•ญ์ƒ ์‰ผํ‘œ ์ถ”๊ฐ€ ์—ฌ๋ถ€ ์„ค์ •.
bracketSpacing: true ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด์—์„œ ์ค‘๊ด„ํ˜ธ ์‚ฌ์ด ๊ณต๋ฐฑ ์ถ”๊ฐ€ ์—ฌ๋ถ€ ์„ค์ •.
semi: true ๋ฌธ์žฅ ๋์— ์„ธ๋ฏธ์ฝœ๋ก  ์ถ”๊ฐ€ ์—ฌ๋ถ€ ์„ค์ •.
arrowParens: always ํ™”์‚ดํ‘œ ํ•จ์ˆ˜์˜ ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ€ ํ•˜๋‚˜์ธ ๊ฒฝ์šฐ์—๋„ ๊ด„ํ˜ธ ์‚ฌ์šฉํ•˜์ง€ ์—ฌ๋ถ€ ๊ฒฐ์ •.
endOfLine: lf ์ค„ ๋ฐ”๊ฟˆ ๋ฌธ์ž ์ง€์ •.
lf ์‚ฌ์šฉ ์‹œ Unix ์Šคํƒ€์ผ์˜ ์ค„ ๋ฐ”๊ฟˆ ์‚ฌ์šฉ.
proseWrap: preserve markdown ํŒŒ์ผ์—์„œ ํ…์ŠคํŠธ ์ค„ ๋ฐ”๊ฟˆ ์œ ์ง€ ์—ฌ๋ถ€ ์„ค์ •.


์ด๋Ÿฌํ•œ ์„ค์ •์„ ํ†ตํ•ด Prettier๋Š” ์ผ๊ด€๋œ ์ฝ”๋“œ ์Šคํƒ€์ผ์„ ์œ ์ง€ํ•˜๊ณ , ์ฝ”๋“œ ๋ฒ ์ด์Šค๋ฅผ ๋ณด๋‹ค ๊น”๋”ํ•˜๊ฒŒ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•  ์ˆ˜ ์žˆ์–ด์š”.

๋‹ค๋งŒ, ์‚ฌ์šฉํ•˜๋Š” IDE์— ์ด๊ฒƒ์— ๋งž๋Š” eslint, prettierlint ์„ค์ •์„ ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.

InteliJ ->&nbsp;Settings > Languages & Frameworks > javascript > Code Quality Tools > ESLint

 
์œ„์™€ ๊ฐ™์ด ํ”„๋กœ์ ํŠธ ๋‚ด์— eslint ํŒŒ์ผ์ด ์žˆ์œผ๋ฉด ํ•ด๋‹น ํŒŒ์ผ์„ ESLint ํŒจํ‚ค์ง€์—์„œ ์ˆ˜๋™ ์„ค์ •์œผ๋กœ ์„ ํƒํ•˜๊ณ ,
ํ•ด๋‹น ํŒŒ์ผ์„ ์ง€์ •ํ•ด ์ฃผ๋ฉด ๋ผ์š”.

โˆ™ eslint package(ESLint ํŒจํ‚ค์ง€): eslint๊ฐ€ ์„ค์น˜๋œ ๊ฒฝ๋กœ ์ง€์ •.
โˆ™ configuration file(๊ตฌ์„ฑ ํŒŒ์ผ): ํ”„๋กœ์ ํŠธ ๋‚ด eslint file์˜ ๊ฒฝ๋กœ (eslint.json ๊ฒฝ๋กœ).
โˆ™ Run eslint --fix on save(์ €์žฅ ์‹œ enlint --fix ์‹คํ–‰) ํ™œ์„ฑํ™”

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
๋งŒ์•ฝ eslint Error๋กœ "linebreak-style"์ด ๋ฐœ์ƒํ•œ๋‹ค๋ฉด eslint.json์— "linebreak-style": 0 ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์„ธ์š”.

 

InteliJ -> Settings > Languages & Frameworks > javascript > Code Quality Tools > Prettier


Prettier ์„ค์ •๋„ ESLint์™€ ๋งˆ์ฐฌ๊ฐ€์ง€์ธ๋ฐ, Prettier Package์—์„œ ../../../node_modules/prettier๋ฅผ ์„ ํƒํ•ด ์ฃผ๋ฉด ๋ผ์š”.
๊ทธ๋ฆฌ๊ณ , ์ €์žฅ ์‹œ ์‹คํ–‰์„ ํ™œ์„ฑํ™” ํ•ด ์ค๋‹ˆ๋‹ค.



 

 

 

        ๐Ÿ“ฆ Hot Reload ์„ค์ •

์ด๋ฒˆ์—๋Š” ์ „์ฒด ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•  ํ•„์š” ์—†์ด ๋น ๋ฅด๊ฒŒ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์žฌ ์‹คํ–‰ ์‹œ์ผœ์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ํ™œ์„ฑํ™” ํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์„ ํ•ด๋ณด๋ ค ํ•ด์š”.

๊ทธ ์ด๋ฆ„์€ ๋ฐ”๋กœ Hot Reload๋ผ๊ณ  ํ•ด์š”.
Node.js์—์„œ์˜ nodemon๊ณผ ๊ฐ™์€ ์—ญํ• ์„ ์œ„ํ•ด ์„ค์ •ํ•ด ์ฃผ๋Š” ๋ถ€๋ถ„์ด์—์š”.

๊ณต์‹ ๋ฌธ์„œ์—์„œ๋Š” Nest CLI๋ฅผ ์„ค์น˜ํ–ˆ์„ ๋•Œ์™€ ์•ˆ ํ–ˆ์„ ๋•Œ๋ฅผ ๋‚˜๋ˆ„์–ด ์„ค๋ช…ํ•ด ์ฃผ๋Š”๋ฐ, ์ฃผ๋‹ˆ๋Š” ์œ„์—์„œ Nest CLI๋ฅผ ์„ค์น˜ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ๊ตฌ์„ฑํ•  ๊ฑฐ์—์š”.

npm i --save-dev webpack-node-externals run-script-webpack-plugin webpack


์œ„์™€ ๊ฐ™์ด ํ•„์š” ํŒจํ‚ค์ง€๋“ค์„ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.


webpack-hmr.config.js


ํ”„๋กœ์ ํŠธ Root(๋ฃจํŠธ) ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์œ„์™€ ๊ฐ™์ด ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.


main.ts


๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด HMR(Hot-Module-Replacement) ํ™œ์„ฑํ™”๋ฅผ ์œ„ํ•ด
main.ts์— Webpack(์›นํŒฉ) ๊ด€๋ จ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

packge.json


๊ทธ๋ฆฌ๊ณ  ์‹คํ–‰์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์œ„์™€ ๊ฐ™์ด script ๋ฌธ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.

์—ฌ๊ธฐ๊นŒ์ง€ ํ•œ ๋’ค ํ„ฐ๋ฏธ๋„์—์„œ npm run start:dev ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.

npm run start:dev


๊ทธ๋Ÿผ ์œ„์™€ ๊ฐ™์ด ์ •์ƒ์ ์œผ๋กœ ๊ตฌ๋™๋˜๋Š” ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.






        ๐Ÿ“ฆ TypeORM

npm i typeorm @nestjs/typeorm


๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด Nest.js์—์„œ ์‚ฌ์šฉํ•  TypeORM์„ ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ฐธ๊ณ ๋กœ ์ฃผ๋‹ˆ๊ฐ€ ์‚ฌ์šฉํ•œ TypeORM Version์€ 0.3.17์ด๊ธฐ ๋•Œ๋ฌธ์— 0.2.X Version์„ ์‚ฌ์šฉํ•˜์‹ ๋‹ค๋ฉด
๋ฐฉ๋ฒ•์ด ๊ฝค๋‚˜ ๋‹ค๋ฅด๋‹ค๋Š” ์  ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

 

 

 

 

        ๐Ÿ“ฆ GraphQL(feat.Apollo)

์ด๋ฒˆ์—๋Š” GraphQL ์‚ฌ์šฉ์„ ์œ„ํ•œ ํŒจํ‚ค์ง€์™€ Apollo ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.

 

npm i @nestjs/apollo graphql-tools graphql @apollo/server

 

npm i @nestjs/graphql graphql-tools graphql apollo-server-express

728x90



app.module.ts (์ˆ˜์ • ์ „)


ํŒจํ‚ค์ง€ ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์œ„์™€ ๊ฐ™์ด app.module.ts๊ฐ€ ์กด์žฌํ• ํ…๋ฐ, ์ด ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•ด ์ฃผ๋„๋ก ํ• ๊ฒŒ์š”.

app.module.ts (์ˆ˜์ • ํ›„)

์œ„์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•ด ์ฃผ์—ˆ๋Š”๋ฐ, ์ฝ”๋“œ ๋ถ„์„์„ ํ•ด๋ณผ๊ฒŒ์š”.

 

์ข…   ๋ฅ˜ ์ƒ ์„ธ ๋‚ด ์šฉ
์ฒซ๋ฒˆ์งธ ์ค„ @nestjs/common์—์„œ Module Decorator Import.
Module Decorator๋Š” Nest.js Module ์ •์˜ ์‹œ ์‚ฌ์šฉ.
๋‘๋ฒˆ์งธ ~ ์„ธ๋ฒˆ์งธ ์ค„ AppController, AppServer Import.
ํ•ด๋‹น Module์€ AppController์™€ AppService Class๋ฅผ ํ•ด๋‹น Module์—์„œ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๊ณ  ์„ ์–ธ.
๋„ค๋ฒˆ์งธ ์ค„ GraphQLModule Import.
7๋ฒˆ์งธ ์ค„ imports ๋ฐฐ์—ด์— ํ•ด๋‹น Module์„ ์ถ”๊ฐ€ํ•˜์—ฌ GraphQL ๊ธฐ๋Šฅ ํ™œ์„ฑํ™”.
์•„ํ™‰๋ฒˆ์งธ ์ค„ autoSchemaFile Option์€ Schema๋ฅผ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•˜๊ณ , File๋กœ ์ €์žฅํ•˜๋„๋ก ์„ค์ •ํ•œ ๋ถ€๋ถ„.
์ด๋ฅผ ํ†ตํ•ด GraphQL Schema๋ฅผ ์ง์ ‘ ์ž‘์„ฑํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์„ ์ค„์ผ ์ˆ˜ ์žˆ์Œ.
์—ด๋‘๋ฒˆ์งธ ์ค„ controller ๋ฐฐ์—ด์—๋Š” AppController๋ฅผ ๋“ฑ๋กํ•˜์—ฌ ํ•ด๋‹น Controller Module์— ํฌํ•จ.
์—ด์„ธ๋ฒˆ์งธ ์ค„ providers ๋ฐฐ์—ด์—๋Š” AppService๋ฅผ ๋“ฑ๋กํ•˜์—ฌ ํ•ด๋‹น Service๋ฅผ Module์— ํฌํ•จ.


์œ„์™€ ๊ฐ™์ด Nest.js์˜ ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ฅผ ์ •์˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ app.moudle.ts์ธ๋ฐ, ์ด ๊ณณ์— GraphQL ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ Module(๋ชจ๋“ˆ)์„ ์„ค์ •ํ•ด ์ค€ ๊ฒƒ์ด์—์š”.

์œ„ ์„ค์ •์œผ๋กœ ์ธํ•ด GraphQL Schema(์Šคํ‚ค๋งˆ)๋Š” ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๊ฒŒ ๋  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ณ„๋„ ์Šคํ‚ค๋งˆ File(ํŒŒ์ผ) ์ž‘์„ฑ ์ž‘์—…์€ ํ•„์š”๊ฐ€ ์—†๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

npm run start:dev


์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๊ณ , ์„œ๋ฒ„๋ฅผ ๊ตฌ๋™ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ๊ฑฐ์—์š”.
์ด์œ ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ํ•˜๋‚˜ ์ด์ƒ์˜ Query Root Type์ด ํ•„์š”ํ•œ๋ฐ, ๊ทธ๊ฒŒ ์—†๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.






        ๐Ÿ“ฆ Logger(Middlewares)

์ด๋ฒˆ์—๋Š” Log(๋กœ๊ทธ) ๊ด€๋ฆฌ๋ฅผ ์œ„ํ•œ Middleware(๋ฏธ๋“ค์›จ์–ด)๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.
morgan, winston์ฒ˜๋Ÿผ ๋กœ๊ทธ ๊ด€๋ฆฌ ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์ฃผ๋‹ˆ๋Š” ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.

mkdir src/middlewares; touch src/middlewares/logger.middlewares.ts


์œ„์™€ ๊ฐ™์ด ๋””๋ ‰ํ„ฐ๋ฆฌ์™€ ts ํŒŒ์ผ์„ ๋จผ์ € ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

logger.middlewares.ts


์œ„ ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•ด ๋ณผ๊ฒŒ์š”.

4๋ฒˆ์งธ ์ค„์— @Injectable()์€ Nest.js์—์„œ ์˜์กด์„ฑ ์ฃผ์ž…์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ Decorator(๋ฐ์ฝ”๋ ˆ์ดํ„ฐ)์—์š”.
์ด ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๊ฐ€ ๋ถ™์€ Class(ํด๋ž˜์Šค)๋Š” Nest.js์—์„œ ๊ด€๋ฆฌ๋˜๋Š” ์„œ๋น„์Šค๋กœ ์ทจ๊ธ‰๋˜๊ฒŒ ๋ผ์š”.

nest-middleware.interface.d.ts


์ด๊ฒƒ์„ ๊ตฌํ˜„ํ•œ ์ด์œ ๋Š” Nest.js์—์„œ ๋ฏธ๋“ค์›จ์–ด๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ Interface(์ธํ„ฐํŽ˜์ด์Šค)์ด๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.

6๋ฒˆ์งธ ์ค„ Logger๋Š” Nest.js์—์„œ ์ œ๊ณตํ•˜๋Š” ๋กœ๊ทธ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ๊ฐ์ฒด์—์š”.
HTTP๋ฅผ ์ž…๋ ฅํ•œ ์ด์œ ๋Š” ์ด ๋กœ๊ทธ๊ฐ€ ์–ด๋–ค ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•˜๋Š”์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด์ฃผ๊ธฐ ์œ„ํ•จ์ด์—์š”.

8 ~ 19๋ฒˆ์งธ ์ค„๊นŒ์ง€์˜ use()๋Š” NestMiddleware ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์š”๊ตฌ๋˜๋Š” Method(๋ฉ”์„œ๋“œ)๋กœ

๋ชจ๋“  ๋ฏธ๋“ค์›จ์–ด ๋กœ์ง์ด ํฌํ•จ๋˜๋Š” ๋ฉ”์„œ๋“œ์—์š”.

request๋Š” Express.js์˜ Request ๊ฐ์ฒด๋กœ,
Client(ํด๋ผ์ด์–ธํŠธ)์—์„œ Server(์„œ๋ฒ„)๋กœ ๋“ค์–ด์˜ค๋Š” HTTP ์š”์ฒญ๊ณผ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ์–ด์š”.

response๋Š” Express.js์˜ Response ๊ฐ์ฒด๋กœ,
์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ๋กœ ๋‚˜๊ฐ€๋Š” HTTP ์‘๋‹ต๊ณผ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ๊ฐ์ฒด์—์š”.

next๋Š” ๋ฏธ๋“ค์›จ์–ด์˜ ์‹คํ–‰์ด ๋๋‚˜๋ฉด ๋‹ค์Œ ๋ฏธ๋“ค์›จ์–ด๋‚˜, Router(๋ผ์šฐํ„ฐ)๋กœ ์ œ์–ด๋ฅผ ๋„˜๊ธฐ๊ธฐ ์œ„ํ•œ Call Back(์ฝœ๋ฐฑ) ํ•จ์ˆ˜์—์š”.


9 ~ 16๋ฒˆ์งธ ์ค„๊นŒ์ง€๋ฅผ ๋ถ„์„ํ•ด๋ณผ๊ฒŒ์š”.
์ด ๋ถ€๋ถ„์€ HTTP ์š”์ฒญ๊ณผ ์‘๋‹ต์— ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ์ถ”์ถœํ•˜๊ณ ,
์‘๋‹ต์ด ์™„๋ฃŒ(Finish Event) ๋˜๋ฉด ํ•ด๋‹น ์ •๋ณด๋ฅผ ๋กœ๊ทธ์— ์ถœ๋ ฅํ•˜๋„๋ก ํ•ด ์ค€ ๋ถ€๋ถ„์ด์—์š”.

request.get("user-agent") || :""
์ด ๋ถ€๋ถ„์€ ์š”์ฒญ์˜ user-agent Header(ํ—ค๋”)์—์„œ User Agent ์ •๋ณด๋ฅผ ์ถ”์ถœํ•˜๋Š” ๋ถ€๋ถ„์ด์—์š”.

response.on("finish", () => { ... })
์ด ๋ถ€๋ถ„์€ ์‘๋‹ต์ด ์™„๋ฃŒ๋  ๋•Œ ์‹คํ–‰ํ•˜๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ๋“ฑ๋กํ•ด ์ค€ ๋ถ€๋ถ„์ด์—์š”.

this.logger.log(...)
์ด ๋ถ€๋ถ„์€ ์œ„์—์„œ ์„ค์ •ํ•œ Logger๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•˜๋„๋ก ํ•ด ์ค€ ๋ถ€๋ถ„์ด์—์š”.

์ด๋ฅผ ํ†ตํ•ด HTTP ์š”์ฒญ์— ๋Œ€ํ•œ ๋กœ๊น…์ด ๋˜๋„๋ก ํ•ด ์ค€ ๋ถ€๋ถ„์ด์—์š”.

 

 

 

 

        ๐Ÿ“ฆ SQLite Embedded Mode

์ด๋ฒˆ์—๋Š” DBMS๋ฅผ ์„ค์น˜ํ•ด๋ณผ๊ฑด๋ฐ, ์žํ”„๋ง์—์„œ๋„ ๊ทธ๋žฌ๋“ฏ์ด
SQLite3 DBMS๋ฅผ Embedded Mode๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์„ค์น˜ ๋ฐ ์„ค์ •์„ ํ•ด๋ณผ๊ฑฐ์—์š”.

npm i --save sqlite3

 

app.module.ts




app.module.ts

 
๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด TypeOrmModule.forRoot๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค์ •์„ ์ •์˜ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

๋‚ด์šฉ์„ ๋ณด๋ฉด type์„ sqlite๋กœ ํ•˜๊ณ , database๋ฅผ :memory:๋กœ ์„ค์ •ํ•˜๊ณ  ์žˆ์–ด์š”.
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด Memory์— ๊ฐ’์„ ์ €์žฅํ•˜๊ฒŒ ๋˜๋Š”๋ฐ,
ํŒŒ์ผ ์ €์žฅ ๋‚ด์šฉ์„ ํ™•์ธํ•  ๋ฐฉ๋ฒ•์ด ์—†์–ด์š”.

๊ทธ๋ž˜์„œ ์•„๋ž˜์—์„  File๋กœ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•˜๋ ค๊ณ  ํ•ด์š”.


๊ทธ๋ฆฌ๊ณ , synchronize๋ฅผ true๋กœ ์„ค์ •ํ•˜์—ฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์Šคํ‚ค๋งˆ๋ฅผ ์ž๋™์œผ๋กœ ๋™๊ธฐํ™” ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.
๋‹ค๋งŒ, ์ด๋Š” ์‹ค์ œ ์šด์˜ ํ™˜๊ฒฝ์—์„œ๋Š” false๋กœ ํ•˜๋Š”๊ฑธ ์ถ”์ฒœํ•ด์š”.

 

 

        ๐Ÿ“ฆ @nestjs/config & Joi

์ด๋ฒˆ์—๋Š” Nest.js์—์„œ .env๋ฅผ ์ด์šฉํ•ด Embedded SQLite File Save Mode ์„ค์ •์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.

npm i dotenv


์ตœ์ดˆ .env ํŒŒ์ผ ํŒŒ์‹ฑ์„ ์œ„ํ•ด dotenv ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค ํ”„๋กœ์ ํŠธ Root(๋ฃจํŠธ) ๋””๋ ‰ํ„ฐ๋ฆฌ์— .env ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.

.env


๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด ์ž‘์„ฑํ•ด ์ฃผ๋Š”๋ฐ ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด DB_HOST ๊ฐ’์ด ./graphql-test.db์ธ ์„ค์ •์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.



src/common/config/sqlite/sqlite-config.provider.ts


๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด ConfigProvider๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.
์ด ์ฝ”๋“œ๋Š” TypeOrmOptionsFactory๋ฅผ ๊ตฌํ˜„ํ•˜์—ฌ SQLite DB์— ๋Œ€ํ•œ ์„ค์ •์„ ์ œ๊ณตํ•˜๋Š” SqpliteConfigProvide์—์š”.


์ฝ”    ๋“œ ์ƒ์„ธ ๋‚ด์šฉ ํ•˜์œ„ ์ฝ”๋“œ ์ƒ์„ธ ๋‚ด์šฉ
@Injectable() ํด๋ž˜์Šค๊ฐ€ ์ฃผ์ž… ๊ฐ€๋Šฅํ•œ ์„œ๋น„์Šค์ž„์„ ๋‚˜ํƒ€๋ƒ„.    
constructor(private configService:
ConfigService) {}
ํด๋ž˜์Šค ์ƒ์„ฑ์ž์—์„œ configService๋ฅผ ์ฃผ์ž… ๋ฐ›์•„ ํ™˜๊ฒฝ ๋ณ€์ˆ˜์™€ ๊ฐ™์€ ์„ค์ • ๊ฐ’ ์ œ๊ณต.    
createTypeOrmOptions():
TypeOrmModuleOptions
TypeOrmOptionsFactory ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•œ ๋ฉ”์„œ๋“œ๋กœ TypeORM ๋ชจ๋“ˆ์˜ ์˜ต์…˜ ์ƒ์„ฑ    
    type:"sqlite" ์‚ฌ์šฉํ•  DB ์œ ํ˜• ์ง€์ •
    database: this.configService.get("DB_HOST", ":memory:") DB์˜ ํŒŒ์ผ ๊ฒฝ๋กœ ๋˜๋Š” :memory: (In Memory Mode)๋ฅผ ์„ค์ •. configService.get()์—์„œ DB_HOST ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๋ฉฐ, ๊ฐ’์ด ์—†์„ ๊ฒฝ์šฐ :memory:๋ฅผ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ
    synchronize: true ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ ์‹œ DB ์Šคํ‚ค๋งˆ๋ฅผ ์ž๋™์œผ๋กœ ๋™๊ธฐํ™”ํ• ์ง€ ์—ฌ๋ถ€ ์„ค์ •.

์šด์˜ ํ™˜๊ฒฝ์ผ ๊ฒฝ์šฐ ๋ฐ˜๋“œ์‹œ false๋กœ ์ง€์ •.
    entities:[...] TypeORM์ด Entity ํด๋ž˜์Šค๋“ค์„ ์ฐพ์„ ์œ„์น˜ ์„ค์ •.
    migrations: [...] Migraion ํŒŒ์ผ ๊ฒฝ๋กœ ์„ค์ •. Migraion์€ DB ์Šคํ‚ค๋งˆ ๋ณ€๊ฒฝ ๊ด€๋ฆฌ์— ์‚ฌ์šฉ.
    migrationsTableName: "migraions" Migraion Table ์ด๋ฆ„ ์„ค์ •.

ํ•ด๋‹น Table์€ Migraion์˜ ์‹คํ–‰ ์ƒํƒœ ์ถ”์ ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ.

 

 

์ด์ œ Joi ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด๋ณผ๊ฑฐ์—์š”.
Joi๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ๊ฒ€์ฆ์„ ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ฃผ๋Š” ์นœ๊ตฌ์—์š”.

npm i joi


์ตœ์ดˆ ์œ„ ๋ช…๋ น์–ด๋กœ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.


src/common/config/config.validator.ts


๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.
์ด ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ConfigModule์˜ ์„ค์ •์„ ์ •์˜ํ•ด ์ฃผ๋Š” ์ฝ”๋“œ์—์š”.

์ฝ”    ๋“œ ์ƒ์„ธ ๋‚ด์šฉ
ConfigModuleOptions:  ConfigModule์— ๋Œ€ํ•œ ์˜ต์…˜ ์ •์˜ ์ธํ„ฐํŽ˜์ด์Šค.
validationScheam ์„ค์ • ๊ฐ’์˜ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•œ Joi ์Šคํ‚ค๋งˆ.
ํ•ด๋‹น ์ฝ”๋“œ์—์„œ๋Š” DB_HOST๊ฐ€ ๋ฌธ์ž์—ด์ด๋ฉฐ, ํ•„์ˆ˜(required())๊ฐ’์ž„์„ ๋ช…์‹œ.
Joi.object({ ... }) DB_HOST๋ผ๋Š” Key์— ๋Œ€ํ•œ Joi ์Šคํ‚ค๋งˆ ์ •์˜.
isGlobal: true ์„ค์ • ๋ชจ๋“ˆ์„ ์ „์—ญ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋ช…์‹œ.
์ด๋ฅผ ํ†ตํ•ด ์–ด๋””์„œ๋“ ์ง€ ConfigService๋ฅผ ์ฃผ์ž… ๋ฐ›์•„ ์„ค์ • ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Œ.

 

 


 

npm i @nestjs/config


๊ทธ๋Ÿฐ ๋’ค @nestjs/config ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.

์ด์ œ ConfigModule์„ ์„ค์ •ํ•ด ๋ณผ๊ฒŒ์š”. app.module.ts์— ์•„๋ž˜์™€ ๊ฐ™์ด ConfigModule ์„ค์ •์„ ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.

src/app.module.ts (๋ณ€๊ฒฝ ์ „)


src/app.module.ts (๋ณ€๊ฒฝ ํ›„)


์œ„์™€ ๊ฐ™์ด 14 ~ 16๋ฒˆ์งธ ์ค„์ด ๋ณ€๊ฒฝ๋œ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
app.module.ts๋Š” AppModule์— ๋Œ€ํ•œ ์ •์˜๋ฅผ ํ•˜๋Š” ๊ณณ์ด์—์š”.
์—ฌ๋Ÿฌ ๋ชจ๋“ˆ๊ณผ ์„ค์ •์ด ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜์–ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ฃผ์š” ์„ค์ •์„ ์ œ๊ณตํ•˜๋Š” ๋ถ€๋ถ„์ด์—์š”.

์ฝ”    ๋“œ ์ƒ์„ธ ๋‚ด์šฉ
ConfigModule.forRoot(...) ConfigModule ์„ค์ •.
CONFIG_VALIDATOR ๊ฐ์ฒด๋Š” ConfigModule์˜ ์˜ต์…˜์œผ๋กœ ์‚ฌ์šฉ๋˜๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์ฝ๊ณ , ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์ง„ํ–‰.
TypeOrmModule.forRootAsync({ ... }) TypeORM ์„ค์ • ๋ถ€๋ถ„.
SpliteConfigProvider ํด๋ž˜์Šค๋Š” TypeOrmOptionsFactory๋ฅผ ๊ตฌํ˜„ํ•˜๊ณ , SQLite DB์— ๋Œ€ํ•œ ์„ค์ •์„ ๋™์ ์œผ๋กœ ์ œ๊ณต.
GraphQLModule.forRoot< .. >({ ... }) GraphQL ์„œ๋ฒ„ ์„ค์ • ๋ถ€๋ถ„.
ApolloDriver๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Apollo ์„œ๋ฒ„ ์„ค์ • ๋ฐ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ๋Š” GpahQL Playgourd ํ™œ์„ฑํ™”.



 

 

        ๐Ÿ“ฆ TypeORM Sedding

์žํ”„๋ง์—์„œ๋Š” data.sql๊ณผ schema.sql์„ ๋งŒ๋“ค์–ด ๋ฏธ๋ฆฌ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ H2 DBMS์— ๋„ฃ์–ด๋‘๊ณ , ์„œ๋ฒ„๊ฐ€ ๊ธฐ๋™๋˜๋ฉด ์ž๋™์œผ๋กœ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๊ฒŒ ์„ค์ •ํ•ด ๋‘์—ˆ์–ด์š”.

Nest.js์—์„œ๋Š” ์ด์™€ ๊ฐ™์€ ์—ญํ• ์„ Seeding์ด๋ผ๊ณ  ๋ถ€๋ฅด๋Š”๋ฐ, ์ง„ํ–‰ํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

npm i typeorm-extension --save


์ตœ์ดˆ ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด ์ค๋‹ˆ๋‹ค.


package.json


๊ทธ๋ฆฌ๊ณ  ์œ„์™€ ๊ฐ™์ด 21 ~ 22๋ฒˆ์งธ ์ค„์˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.

 

data-source.ts


typeorm-extension์€ typeorm์˜ dataSource๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด Data-source.ts๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.
ํ”„๋กœ์ ํŠธ์˜ ๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ฐธ๊ณ ๋กœ typeorm-extension์€ DataSource ํŒŒ์ผ์˜
๊ธฐ๋ณธ ๊ฒฝ๋กœ๋กœ ๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ data-source.ts ํŒŒ์ผ์„ ์ฐพ๊ฒŒ ๋˜์–ด ์žˆ์–ด์š”.
๋ฌผ๋ก  ์ด ๋ถ€๋ถ„์€ Customํ•˜๊ฒŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์–ด์š”.

๊ทธ๋ฆฌ๊ณ , typeorm-extension seed ๋ช…๋ น์–ด๋Š” seeder ํŒŒ์ผ์˜ ๊ธฐ๋ณธ ๊ฒฝ๋กœ๋ฅผ src/database/seeds/**/*{.ts,.js}๋กœ ๊ฐ€์ง€๊ณ  ์žˆ์–ด์š”. ์ด ๋˜ํ•œ Customํ•˜๊ฒŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์–ด์š”.


src/app/equipment/model/entities/equipment.entity.ts

๋ฐ˜์‘ํ˜•


์œ„์™€ ๊ฐ™์ด euqipment์˜ Entity๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.

์ž˜ ์„ค์ •์ด ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด Equipment Entity์— ๋Œ€ํ•œ ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ ์‚ฝ์ž…์„ ์œ„ํ•ด src/database/seeds/equipment.seeder.ts๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.

์ด ๊ณณ์— ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์„์ง€ ์ •์˜ํ•˜๋ฉด ๋œ๋‹ต๋‹ˆ๋‹ค.

src/database/seeds/equipment.seeder.ts


์ด ์ฝ”๋“œ๋„ ๋ถ„์„ํ•ด ๋ณด๋ฉด TypeORM Extension์˜ Seeder๋ฅผ ๊ตฌํ˜„ํ•œ EquipmentSeeder ํด๋ž˜์Šค์—์š”.
์ด๊ฒƒ์„ ํ†ตํ•ด ์„œ๋ฒ„๊ฐ€ ๊ธฐ๋™๋  ๋•Œ, ๋ฏธ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๊ฐ’์„ ๋„ฃ์–ด๋‘˜ ์ˆ˜ ์žˆ์–ด์š”.

์ตœ์ดˆ 5๋ฒˆ์งธ ์ค„์€ Seeder ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” EquipmentSeeder ํด๋ž˜์Šค๋ฅผ ์ •์˜ํ•ด์ค€ ๋ถ€๋ถ„์ด์—์š”.

๊ทธ๋ฆฌ๊ณ , 6๋ฒˆ์งธ ์ค„์€ Seeder ์ธํ„ฐํŽ˜์ด์Šค์—์„œ ์ •์˜๋œ run ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ถ€๋ถ„์ธ๋ฐ, ์ด ๋ฉ”์„œ๋“œ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์‚ฝ์ž…ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์„œ๋“œ์—์š”.

7๋ฒˆ์งธ ์ค„์€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ EuqipmentEntity์— ๋Œ€ํ•œ Repository(๋ ˆํฌ์ง€ํ† ๋ฆฌ)๋ฅผ ๊ฐ€์ ธ์˜ค๋„๋กํ•œ ๋ถ€๋ถ„์ด์—์š”.
์ด๊ฒƒ์„ ์ด์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฝ์ž…ํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•จ์ด์—์š”.

8๋ฒˆ์งธ ์ค„ ๋ถ€ํ„ฐ 15๋ฒˆ์งธ ์ค„๊นŒ์ง€๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ insert ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ
์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๊ฐ’์„ ์‚ฝ์ž…ํ•ด ์ฃผ๊ธฐ ์œ„ํ•œ ๋ถ€๋ถ„์ด์—์š”.

๊ทธ ๊ฐ’์ด ์—ฌ๋Ÿฌ๊ฐœ์ด๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด ์—ฌ๋Ÿฌ๊ฐœ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด๋ ‡๊ฒŒ Seeder ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ์ž…ํ•˜๊ฑฐ๋‚˜, ํ…Œ์ŠคํŠธ์šฉ ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.



npm run seed:run


์œ„ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด


์œ„์™€ ๊ฐ™์ด ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ๋””๋ ‰ํ„ฐ๋ฆฌ์— grahpql-test.db๊ฐ€ ์ƒ๊ธด๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.

์ด ํŒŒ์ผ์„ ํด๋ฆญํ•˜๋ฉด 


์œ„์™€ ๊ฐ™์ด ์ธํ…”๋ฆฌ์ œ์ด์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ์ฐฝ์ด ๋‚˜์˜ค๊ณ ,
๋“œ๋ผ์ด๋ฒ„๋ฅผ ๋‚ด๋ ค ๋ฐ›๊ณ , ์—ฐ๊ฒฐํ•˜๋ฉด ํ•ด๋‹น ํŒŒ์ผ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.



์ด๋ ‡๊ฒŒ Mock ๋ฐ์ดํ„ฐ๊ฐ€ ์ž˜ ๋“ค์–ด๊ฐ„ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

์ด ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•ด ๋‚˜๋จธ์ง€ ๊ฐ’๋“ค๋„ ๋‹ค ๋„ฃ์–ด์ค„๊ฒŒ์š”.

ํ•˜์ง€๋งŒ, ์—ฌ๊ธฐ์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ด ๋ฒ„๋ ธ์–ด์š”.


ํ•ด๋‹น ๋ฌธ์ œ์— ๋Œ€ํ•œ ์ด์•ผ๊ธฐ๋Š” ์ด ๊ณณ์— ์ƒ์„ธํžˆ ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.

 

[Nest.js] TypeORM Table ๊ด€๊ณ„๊ฐ€ ๋งบ์–ด์กŒ์„ ๋•Œ, Seeding (feat. Migration)

NestJS๋กœ ๋ฐฐ์šฐ๋Š” ๋ฐฑ์—”๋“œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ:ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ™˜๊ฒฝ์˜ ์ฐจ์„ธ๋Œ€ ์„œ๋ฒ„ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋งŒ๋‚˜๋‹ค COUPANG www.coupang.com "์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›

junyharang.tistory.com

 

๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ์œผ๋‹ˆ ๊ธฐ์กด์— typeorm extension์„ ์ด์šฉํ•œ Seeding์—์„œ
Migration์„ ์ด์šฉํ•œ Seeding์œผ๋กœ ๋ชจ๋‘ ๋ฐ”๊ฟ”์ฃผ์—ˆ์–ด์š”.

 

 

        ๐Ÿ“ฆ Pipe

์ด๋ฒˆ์—” ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ์œ„ํ•œ Pipe๋ฅผ ๋งŒ๋“ค์–ด ๋ณด๋ ค๊ณ  ํ•ด์š”.
ํ•ด๋‹น ๋‚ด์šฉ์— ๊ฐœ์š”๋Š” ์ด ๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ๊ฒŒ ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.

 

[BackEnd][Node.js][nest.js-PJ] ์‚ฌ๋‚ด ๊ฐœ๋ฐœ์ž ์ปค๋ฎค๋‹ˆํ‹ฐ ์„œ๋น„์Šค - ์ดˆ๊ธฐ ๊ตฌ์„ฑ(Pipe, TypeORM, Configuration, Swagger, Lo

Project Git Hub ๐Ÿ—‚ ๋ชฉ์ฐจ โ— [BackEnd][Node.js][nest.js-PJ] ์‚ฌ๋‚ด ๊ฐœ๋ฐœ์ž ์ปค๋ฎค๋‹ˆํ‹ฐ ์„œ๋น„์Šค - ์ดˆ๊ธฐ ๊ตฌ์„ฑ(Pipe, TypeORM, Configuration, Swagger, Logger) โ— [BackEnd][Node.js][Nest.js] ์‚ฌ๋‚ด ๊ฐœ๋ฐœ์ž ์ปค๋ฎค๋‹ˆํ‹ฐ ์„œ๋น„์Šค - ํšŒ์› ๊ฐ€์ž…

junyharang.tistory.com

 

 

GraphQL๊ณผ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋กœ ๊ฐœ๋ฐœํ•˜๋Š” ์›น ์„œ๋น„์Šค:์„ค๊ณ„๋ถ€ํ„ฐ ๊ฐœ๋ฐœ·๋ฐฐํฌ๊นŒ์ง€ ๋”ฐ๋ผ ํ•˜๋ฉฐ ์™„์„ฑํ•˜๋Š” ์›น ํ’€

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

GitHub - junyharang-coding-study/GraphQL-Study: GraphQL์„ ๊ณต๋ถ€ํ•˜๊ณ , ์‹ค์Šตํ•œ ์ฝ”๋“œ์—์š” ๐Ÿ˜€

GraphQL์„ ๊ณต๋ถ€ํ•˜๊ณ , ์‹ค์Šตํ•œ ์ฝ”๋“œ์—์š” ๐Ÿ˜€. Contribute to junyharang-coding-study/GraphQL-Study development by creating an account on GitHub.

github.com

 

 

 

 

๐Ÿง ์ฐธ๊ณ  ์ž๋ฃŒ

 

Documentation | NestJS - A progressive Node.js framework

Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Rea

docs.nestjs.com

 

 

NestJS์—์„œ TypeORM์˜ Brackets๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์ž!

์ฒ˜์Œ ๋ชจ๋ฐ”์ผ ์•ฑ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ–ˆ์„ ๋‹น์‹œ ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒํ•œ ์ •๋ ฌ์กฐ๊ฑด๊ณผ ํ•„ํ„ฐ์กฐ๊ฑด์„ ์ ์šฉํ•œ ๊ฒฐ๊ณผ๋ฅผ ์–ป์–ด์•ผ ํ•˜๋Š” ๊ธฐ๋Šฅ์ด ์žˆ์—ˆ๋‹ค. ๊ฐ๊ฐ์˜ ์กฐ๊ฑด๋“ค์„ ๋‹ค ์กฐํ•ฉํ•˜์—ฌ ์กฐํšŒํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์„ ํƒ

velog.io

 

 

NestJS 08 | TypeORM QueryBuilder

๋ณธ๊ฒฉ์ ์œผ๋กœ NestJS๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๋ณต์žกํ•œ Query๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ƒ๊ฒผ์Šต๋‹ˆ๋‹ค. ์ด์— ๋”ฐ๋ผ TypeORM์ด ์ œ๊ณตํ•˜๋Š” QueryBuilder๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ SQL Query๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•ด

velog.io

 

 

Nest.js TypeORM ๋ฆฌํŒฉํ„ฐ๋ง (QueryBuilder)

์ง€๋‚œ๋ฒˆ์—๋Š” TypeORM Repository๋ฅผ DDDํ•˜๊ฒŒ ๋„๋ฉ”์ธ Aggregate ๋ฒ”์œ„์™€ ์ผ์น˜์‹œํ‚ค๋Š” ๋ฒ•์— ์‚ดํŽด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ์—๋Š” TypeORM์—์„œ ์ž์ฃผ ์ด์šฉํ•˜๋Š” QueryBuilder์˜ ์ฝ”๋“œ๋Ÿ‰์„ ์ค„์ด๋Š” ๋ฒ•์— ๋Œ€ํ•ด ์‚ดํŽด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

velog.io

 

 

[Nest.js] DTO ๋ฅผ Entity ๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ (DTO to Entity, feat. class-validator)

์Šคํ”„๋ง์—์„œ ๋ณธ ๋ญ”๊ฐ€ ์ต์ˆ™ํ•œ ๋ฐฉ๋ฒ•์„ ๊ณ๋“ค์ธ Nest.js ์—์„œ์˜ DTO to Entity

velog.io

 

 

 

 

์นด์นด์˜คํŽ˜์ด | ๋งˆ์Œ ๋†“๊ณ  ๊ธˆ์œตํ•˜๋‹ค

์—ฌ๊ธฐ๋ฅผ ๋ˆŒ๋Ÿฌ ๋งํฌ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.

qr.kakaopay.com

 

 

 

728x90
๋ฐ˜์‘ํ˜•