GraphQL๊ณผ Apollo ์—ด ๋‘๋ฒˆ์งธ ์ด์•ผ๊ธฐ - TypeScript + Nest.js์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ - ์‹ค์Šต ํ™˜๊ฒฝ ํ…Œ์ŠคํŠธ

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

728x90
๋ฐ˜์‘ํ˜•

 

 

 

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

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

qr.kakaopay.com

 

 

 

 

 

NestJS๋กœ ๋ฐฐ์šฐ๋Š” ๋ฐฑ์—”๋“œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ:ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ™˜๊ฒฝ์˜ ์ฐจ์„ธ๋Œ€ ์„œ๋ฒ„ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋งŒ๋‚˜๋‹ค

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

 

 

 

 

 

 

๐Ÿš€ GraphQL๊ณผ Apollo ์—ด ๋‘๋ฒˆ์งธ ์ด์•ผ๊ธฐ

    ๐Ÿ”ฝ TypeScript + Nest.js์—์„œ GraphQL ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ

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

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ์ง€๋‚œ ๊ธ€์—์„œ ๋งŒ๋“ค์—ˆ๋˜ GraphQL ํ˜•์‹์˜ Equipment CRUD์— ๋Œ€ํ•ด Schema(์Šคํ‚ค๋งˆ)๋ฅผ ์ž‘์„ฑํ•˜๊ณ , PlayGround๋ฅผ ํ†ตํ•ด Query์™€ Mutation๋ฌธ์„ ๋งŒ๋“ค์–ด Query๋ฅผ ๋˜์ ธ ์ •์ƒ์ ์œผ๋กœ Response(์‘๋‹ต)๊ฐ€ ์˜ค๋Š”์ง€ ํ™•์ธํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

 

 

 

    ๐Ÿ”ฝ Schema

        ๐Ÿ“ฆ Query - getEquipmentList()

src/graphql/schema/schema.graphqls


์ตœ์ดˆ type Root Query๋ฅผ ๋ณด๋ฉด getEquipmentList()์™€ getEquipment()๊ฐ€ ์„ ์–ธ ๋˜์–ด ์žˆ๋Š”๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.
์ด ํ•จ์ˆ˜ ์ด๋ฆ„์€ Resolver(๋ฆฌ์กธ๋ฒ„)์˜ Method(๋ฉ”์„œ๋“œ) ์ด๋ฆ„๊ณผ ๋˜‘๊ฐ™์•„์•ผ ํ•ด์š”.

getEquipmentList()๋Š” usedBy, newOrUsed, page, perPageSize, orderBy๋ฅผ ์ธ์ž๊ฐ’์œผ๋กœ ๋ฐ›์•„์š”.
์ด ๋ถ€๋ถ„์— ๋Œ€ํ•œ ์ƒ์„ธ ๋‚ด์šฉ์€ ์ด ์ „ ๊ธ€์—์„œ Resolver๋ฅผ ์ด์•ผ๊ธฐ ํ•  ๋•Œ, ์ž์„ธํžˆ ์ด์•ผ๊ธฐ ํ•ด ๋ณด์•˜์–ด์š”.

์ฆ‰, ๋ฆฌ์กธ๋ฒ„์˜ ๋ฉ”์„œ๋“œ์˜ ์ด๋ฆ„๊ณผ ๋งค๊ฐœ ๋ณ€์ˆ˜, ๋ฐ˜ํ™˜ Type(ํƒ€์ž…)์ด ์ผ์น˜ํ•ด์•ผ ํ•ด์š”.


src/graphql/schema/equipment/equipment.graphqls


getEquipmentList()์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…์€ ์œ„์™€ ๊ฐ™์ด ์„ ์–ธ ๋˜์–ด ์žˆ์–ด์š”.
HTTP Status Code๋ฅผ ์ •์ˆ˜๋กœ ๋ฐ›๊ณ ,
์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ›๋Š”๋ฐ, ! ๋Š๋‚Œํ‘œ๋Š” Null์ด๋ฉด ์•ˆ๋œ๋‹ค๋Š” ์˜๋ฏธ.
์ฆ‰, ๋ฌด์กฐ๊ฑด ๊ฐ’์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค๋Š” ์˜๋ฏธ์—์š”.

src/graphql/schema/equipment/equipment.graphqls


pagination ์†์„ฑ์€ ์œ„ type์„ ์ž๋ฃŒํ˜•์œผ๋กœ ์ •์˜ํ•ด ๋‘์—ˆ๋Š”๋ฐ,
Paging ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋‹ด์€ ์ •์ˆ˜ ํƒ€์ž…์˜ ๋ณ€์ˆ˜๋“ค๊ณผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ ์กฐํšŒ๋œ ๊ฒฐ๊ณผ๋ฅผ ๋‹ด์€
EquipmentResponseDto ๊ฐ์ฒด๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ›๊ฒ ๋‹ค๊ณ  ์„ ์–ธํ•ด ์ฃผ์—ˆ์–ด์š”.


src/graphql/schema/equipment/equipment.graphqls


data ์†์„ฑ์˜ ๊ฐ’์€ ์œ„ ์ž๋ฃŒํ˜• ํƒ€์ž…์ธ๋ฐ, equipmentId, usedBy, count, newOrused๋ผ๋Š”
์‹ค์ œ ๋ฐ์ดํ„ฐ ๊ฐ’์„ ๊ฐ–์€ DTO๋ฅผ ๋ฐ˜ํ™˜๋ฐ›๊ฒŒ ํ•ด ๋‘์—ˆ์–ด์š”.








        ๐Ÿ“ฆ Query - getEquipment()

src/graphql/schema/schema.graphqls


getEquipment()๋Š” ์ธ์ž๊ฐ’์œผ๋กœ ID๊ฐ’์„ ๋ฌธ์ž์—ด์„ ๋ฐ˜๋“œ์‹œ ๋ฐ›๋„๋กํ•˜๊ณ ,
๋ฐ˜ํ™˜ ํƒ€์ž…์„ FindByEquipmentResponse๋กœ ๋Œ๋ ค์ฃผ๋Š”๋ฐ, ํ•„์ˆ˜๋กœ ๋‚˜์™€์•ผ ํ•˜๋„๋ก ์ •์˜ํ•ด ์ฃผ์—ˆ์–ด์š”.

src/graphql/schema/equipment/equipment.graphqls


FindByEquipmentResponse๋Š” ์œ„์™€ ๊ฐ™์ด HTTP Status Code์™€ Message๋ฅผ ์ฃผ๊ณ ,
data๋กœ๋Š” ResponseDto๋ฅผ ์ฃผ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.


src/graphql/schema/equipment/equipment.graphqls






        ๐Ÿ“ฆ Mutaion - saveForEquipment()

src/graphql/schema/schema.graphqls


saveForEquipment()๋Š” EquipmentRequestDto๋ฅผ input ํƒ€์ž…์œผ๋กœ ๋ฐ›๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.



src/graphql/schema/equipment/equipment.graphqls


์žฅ๋น„์— ๋Œ€ํ•œ ์ €์žฅ ์ฒ˜๋ฆฌ ๋กœ์ง์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ชจ๋“  ๊ฐ’์„ ํ•„์ˆ˜๋กœ ๋ฐ›๋„๋ก ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.


src/graphql/schema/equipment/equipment.graphqls


๋ฐ˜ํ™˜ ํƒ€์ž…์€ ์œ„์™€ ๊ฐ™์€๋ฐ, HTTP Status Code์™€ Message๋ฅผ ๋ฐ›๊ณ , data๋กœ๋Š” ํ•ด๋‹น ์ž‘์—…์ด ์ฒ˜๋ฆฌ๋˜๊ณ ,
๋ฐ˜ํ™˜๋œ ID ๊ฐ’์„ ๋ฐ›๊ฒ ๋‹ค๊ณ  ์ •์˜ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ฐธ๊ณ ๋กœ ์ž‘์—…์ด ์‹คํŒจํ•˜๋ฉด data๋Š” ์•„๋ฌด๊ฒƒ๋„ ๋‹ด๊ธฐ์ง€ ์•Š์„ ๊ฑฐ๊ณ , ๋ฌธ์ œ์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด
statusCode์™€ message๋งŒ ๊ฐ’์ด ๋‹ด๊ฒจ์˜ฌ ๊ฒƒ์ด๋ผ์„œ data์—๋Š” ๋Š๋‚Œํ‘œ๋ฅผ ๋ถ™ํžˆ์ง€ ์•Š์•˜์–ด์š”.






        ๐Ÿ“ฆ Mutaion - updateEquipment()

src/graphql/schema/schema.graphqls

 

src/graphql/schema/equipment/equipment.graphqls


update Logic์˜ ๊ฒฝ์šฐ ์ˆ˜์ •ํ•  ๋Œ€์ƒ์„ ์žก์•„์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ID๊ฐ’์€ ํ•„์ˆ˜๋กœ ๋ฐ›์•„์•ผ ํ•˜์ง€๋งŒ,
๋‚˜๋จธ์ง€๋Š” ๋ญ˜ ์ˆ˜์ •ํ• ์ง€ ์•Œ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ๋Š๋‚Œํ‘œ๋ฅผ ๋ถ™ํžˆ์ง€ ์•Š์•˜์–ด์š”.
๋ฐ˜ํ™˜ ๊ฐ’์€ saveForEquipment()์™€ ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.


 

 

 

 

        ๐Ÿ“ฆ Mutaion - deleteEquipment()

src/graphql/schema/schema.graphqls


Delete Logic์˜ ๊ฒฝ์šฐ์—๋„ ์‚ญ์ œ ๋Œ€์ƒ์„ ์žก์•„์ค˜์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ID๊ฐ’์„ ํ•„์ˆ˜ ์ธ์ž๊ฐ’์œผ๋กœ ๋ฐ›์•„์ฃผ๊ณ  ์žˆ์–ด์š”.

๊ทธ๋ฆฌ๊ณ  ๋ฐ˜ํ™˜ ํƒ€์ž…์€ getEquipment()์™€ ๋™์ผํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.

 

 

 

 

    ๐Ÿค” ์ž˜ ๋™์ž‘ํ•˜๋‚˜?

        ๐Ÿ“ฆ PlayGround

์ด์ œ ์ •์ƒ ๋™์ž‘ ์—ฌ๋ถ€๋ฅผ ํ•˜๋‚˜ํ•˜๋‚˜ ํ…Œ์ŠคํŠธ ํ•ด๋ณผ๊ฒŒ์š”.

1. saveForEquipment

mutation saveForEquipment {
  saveForEquipment(input: {
    equipmentId: "MacBook",
    usedBy: "developer",
    count: 100,
    newOrUsed: "new"
  }) {
    statusCode,
    message,
    data
  }
}

 


ํ•ด๋‹น ๋ฌธ๋ฒ•์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ธ€์˜ ์ด ์ „ ์‹œ๋ฆฌ์ฆˆ๋ฅผ ํ†ตํ•ด ๊ณต๋ถ€ํ•ด ๋ณด์•˜์–ด์š”.
GraphQL์— ๋Œ€ํ•ด ์ž˜ ๋ชจ๋ฅด์‹œ๋Š” ๋ถ„์€ ํ•ด๋‹น ์‹œ๋ฆฌ์ฆˆ ์ฒ˜์Œ๋ถ€ํ„ฐ ๊ธ€์„ ๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์š”.

๋ฐ˜์‘ํ˜•



mutation saveForEquipment

 

mutation saveForEquipment



 

2. getEquipmentList - findBygetEquipmentListSeachAllFieldAndPaging

์ด ํ…Œ์ŠคํŠธ๋Š” ์ „์ฒด ์กฐํšŒ๋ฅผ ํ•  ๋•Œ, ๋ชจ๋“  ์š”์†Œ์— ๋Œ€ํ•œ ๊ฒ€์ƒ‰ ๊ฐ’์ด ์žˆ๊ณ , Paging ๊ด€๋ จ ๊ฐ’๋„ ์žˆ์œผ๋ฉฐ, ์ •๋ ฌ์— ๋Œ€ํ•ด ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์กฐํšŒ ํ•ด๋‹ฌ๋ผ๋Š” Request(์š”์ฒญ)์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ์—์š”.

query findBygetEquipmentListSeachAllFieldAndPaging {
  getEquipmentList(
    usedBy: "developer",
    newOrUsed: "used",
  	page: 1,
  	perPageSize: 10,
    orderBy: true
  ) {
    statusCode,
    message,
    pagination{
      perPageSize,
      totalCount,
      totalPage,
      data {
        equipmentId,
        usedBy,
        count,
        newOrUsed
    	}
    }
  }
}

query findBygetEquipmentListSeachAllFieldAndPaging

 

 

 

2-1. getEquipmentList - findeBygetEquipmentListPaging

์ด๋ฒˆ์—๋Š” ๊ฒ€์ƒ‰ ์กฐ๊ฑด์€ ์—†์ด Paging ์ฒ˜๋ฆฌ ์š”์ฒญ๋งŒ ๋“ค์–ด์™”์„ ๋•Œ์—์š”.

query findeBygetEquipmentListPaging {
  getEquipmentList(
    page: 1,
    perPageSize: 10
  ) {
    statusCode,
    message,
    pagination {
      perPageSize,
      totalCount,
      totalPage
      data {
        equipmentId,
        usedBy,
        count,
        newOrUsed
      }
    }
  }
}

 

query findeBygetEquipmentListPaging

 

{
  "data": {
    "getEquipmentList": {
      "statusCode": 200,
      "message": "Success",
      "pagination": {
        "perPageSize": 6,
        "totalCount": 7,
        "totalPage": 2,
        "data": [
          {
            "equipmentId": "pen tablet",
            "usedBy": "developer",
            "count": 15,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "ergonomic mouse",
            "usedBy": "designer",
            "count": 31,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "dual monitor",
            "usedBy": "developer",
            "count": 20,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "whiteboard",
            "usedBy": "planner",
            "count": 12,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "sketchb",
            "usedBy": "designer",
            "count": 48,
            "newOrUsed": "new"
          },
          {
            "equipmentId": "MacBook",
            "usedBy": "developer",
            "count": 100,
            "newOrUsed": "new"
          }
        ]
      }
    }
  }
}

 





2-2. getEquipmentList - findBygetEquipmentListSeachUsedByAndPaging

์ด๋ฒˆ์—๋Š” ๊ฒ€์ƒ‰ ์กฐ๊ฑด์œผ๋กœ usedBy๊ฐ€ ๋“ค์–ด์˜ค๊ณ , Paging ์š”์ฒญ์ด ๋“ค์–ด์™”์„ ๋•Œ์—์š”.

query findBygetEquipmentListSeachUsedByAndPaging {
  getEquipmentList(
    usedBy: "developer",
    page: 1,
    perPageSize: 1
  ) {
    statusCode,
    message,
    pagination {
      perPageSize,
      totalCount,
      totalPage
      data {
        equipmentId,
        usedBy,
        count,
        newOrUsed
    	}
    }
  }
}
728x90

query findBygetEquipmentListSeachUsedByAndPaging





 

2-3. getEquipmentList - findBygetEquipmentListSeachNewOrUsedAndPaging

์ด๋ฒˆ์—๋Š” ๊ฒ€์ƒ‰ ์กฐ๊ฑด์œผ๋กœ newOrUsed๋งŒ ๋“ค์–ด์˜ค๊ณ , Paging ์š”์ฒญ์ด ๋“ค์–ด์™”์„ ๋•Œ์—์š”.

query findBygetEquipmentListSeachNewOrUsedAndPaging {
  getEquipmentList(
    newOrUsed: "used",
    page: 1,
    perPageSize: 10
  ) {
    statusCode,
    message,
    pagination {
      perPageSize,
      totalCount,
      totalPage
      data {
        equipmentId,
        usedBy,
        count,
        newOrUsed
      }
    }
    ,
  }
}

 

query findBygetEquipmentListSeachNewOrUsedAndPaging

 

{
  "data": {
    "getEquipmentList": {
      "statusCode": 200,
      "message": "Success",
      "pagination": {
        "perPageSize": 4,
        "totalCount": 5,
        "totalPage": 2,
        "data": [
          {
            "equipmentId": "pen tablet",
            "usedBy": "developer",
            "count": 15,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "ergonomic mouse",
            "usedBy": "designer",
            "count": 31,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "dual monitor",
            "usedBy": "developer",
            "count": 20,
            "newOrUsed": "used"
          },
          {
            "equipmentId": "whiteboard",
            "usedBy": "planner",
            "count": 12,
            "newOrUsed": "used"
          }
        ]
      }
    }
  }
}






3. getEquipment

์ด๋ฒˆ์—๋Š” ์ƒ์„ธ ์กฐํšŒ ํ…Œ์ŠคํŠธ ํ•ด๋ณผ๊ฒŒ์š”.

query getEquipment {
  getEquipment(
  equipmentId: "machanical keyboard"
  ) {
    statusCode,
    message,
    data {
      equipmentId,
      usedBy,
      count,
      newOrUsed
    }
  }
}

query getEquipment








4. updateEquipment

์ด๋ฒˆ์—๋Š” ์œ„์—์„œ ์ €์žฅํ–ˆ๋˜ equipmentId ๊ฐ’์ด MackBook์ธ ๊ฒƒ์„ ์ˆ˜์ •ํ•ด ๋ณผ๊ฒŒ์š”.

mutation updateEquipment {
  updateEquipment(input: {
    equipmentId: "MacBook",
    usedBy: "developer",
    count: 150
    newOrUsed: "new"
  }) {
    statusCode,
    message,
    data
  }
}

mutation updateEquipment

 

mutation updateEquipment


์œ„์™€ ๊ฐ™์ด ํ•„์ˆ˜๊ฐ’์„ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์œผ๋ฉด ํ•ด๋‹น Field ๊ฐ’์ด ์ •์˜๋˜์ง€ ์•Š์•˜๋‹ค๊ณ  Error๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.


mutation updateEquipment




4. deleteEquipment

์ด๋ฒˆ์—” ๋งŒ๋“ค์–ด์คฌ๋˜ MacBook์— ๋Œ€ํ•œ ๊ฐœ์ฒด๋ฅผ ์‚ญ์ œํ•ด ๋ณผ๊ฒŒ์š”.

mutation deleteEquipment {
  deleteEquipment(
    equipmentId: "MacBook") {
    statusCode,
    message,
    data
  }
}

mutation deleteEquipment





Console


์œ„์™€ ๊ฐ™์ด ์ •์ƒ ์ฒ˜๋ฆฌ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.

Equipment ์™ธ์— ๋‹ค๋ฅธ ๊ฒƒ๋“ค๋„ ์ด์™€ ๋น„์Šทํ•˜๊ฒŒ ๊ตฌ์„ฑ๋  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— Equipment์— ๋Œ€ํ•œ ๋‚ด์šฉ๋งŒ ๋‚จ๊ธฐ๊ณ ,
๋‚˜๋จธ์ง€๋Š” ์ถ”๊ฐ€ ์‹ค์Šต์„ ํ•˜๋ฉด์„œ ์ •๋ฆฌํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

ํ•ด๋‹น ๋‚ด์šฉ์€ ์‹ค์Šต ์ฝ”๋“œ์— src/graphql/query์— ๋‚จ๊ฒจ ๋‘์—ˆ์–ด์š”.


์‹ค์Šตํ•ด๋ณด๊ณ  ์‹ถ์œผ์‹œ๋‹ค๋ฉด Git Hub์— ๋ฐฉ๋ฌธํ•ด ์ฃผ์„ธ์š”.


 

 

 

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

 

 

 

 

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

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

qr.kakaopay.com

 

 

 

728x90
๋ฐ˜์‘ํ˜•