Intro to GraphQL

GraphQL ์‹œ์ž‘ํ•˜๊ธฐ!

https://tech.kakao.com/2019/08/01/graphql-basic/

https://www.slideshare.net/shilpe34/typescript-200-graphql-179690400

GraphQL ์ด๋ž€?

API๋ฅผ ์œ„ํ•œ Query Language!

  • SQL (Structured Query Language) ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ Query Language

    • but, ์–ธ์–ด์  ๊ตฌ์กฐ ์ฐจ์ด๊ฐ€ ํฌ๋‹ค

      • ๊ทธ ๊ฒฐ๊ณผ ์ด ๋‘˜์— ๋Œ€ํ•œ ํ™œ์šฉ์„ ๋‹ค๋ฅด๊ฒŒ ํ•˜๊ฒŒ ๋จ

      • ์‚ฌ์šฉ ๋ชฉ์ 

        • sql : DB ์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์ด ๋ชฉ์ 

        • gql : Web Client ๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ํšจ์œจ์ ์œผ๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๊ฒƒ์ด ๋ชฉ์ 

      • ํ˜ธ์ถœ

        • sql : Backend system ์—์„œ ์ž‘์„ฑํ•˜๊ณ  ํ˜ธ์ถœ

        • gql : Client system ์—์„œ ์ž‘์„ฑํ•˜๊ณ  ํ›„์ถœ

  • ๋‹จ์ผ ์š”์ฒญ์œผ๋กœ ๋งŽ์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ ์˜ฌ ์ˆ˜ ์žˆ๋‹ค

  • ํƒ€์ž… ์‹œ์Šคํ…œ

  • ๊ฐ•๋ ฅํ•œ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ ์ œ๊ณต

Serverside GraphQL application

  • gql ๋กœ ์ž‘์„ฑ๋œ ์ฟผ๋ฆฌ๋ฅผ ์ž…๋ ฅ์œผ๋กœ ๋ฐ›์•„, ์ฟผ๋ฆฌ๋ฅผ ์ฒ˜๋ฆฌํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ client ๋กœ ๋Œ๋ ค์คŒ

  • GraphQL ์„œ๋ฒ„

REST API ์™€ GraphQL API ์˜ ์ฐจ์ด์ 

  • REST API

    • URL, METHOD ๋“ฑ์œผ๋กœ ์กฐํ•ฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์–‘ํ•œ Endpoint ๊ฐ€ ์กด์žฌ

      • ๊ฐ Endpoint ๋งˆ๋‹ค Database SQL query๊ฐ€ ๋‹ฌ๋ผ์ง

  • gql API

    • ๋‹จ ํ•˜๋‚˜์˜ Endpoint๊ฐ€ ์กด์žฌ

    • ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐ์ดํ„ฐ์˜ ์ข…๋ฅ˜๋ฅผ ์ฟผ๋ฆฌ์˜ ์กฐํ•ฉ์„ ํ†ตํ•ด ๊ฒฐ์ •

      • gql schema type ๋งˆ๋‹ค Database SQL query๊ฐ€ ๋‹ฌ๋ผ์ง

๊ตฌ์„ฑ๋œ ์ธํ”„๋ผ, ๋น„์ฆˆ๋‹ˆ์Šค ๋ชจ๋ธ, ์‚ฌ์šฉํ•˜๋Š” ๋ชฉ์ ์— ๋”ฐ๋ผ ๊ฐ๊ฐ์˜ ์žฅ๋‹จ์ ์ด ๋ฐ”๋€๋‹ค!

schema / type

ex)

type Character {
    name: String!
    appearIn: [Episode!]!
}
  • Object type : Character

  • Field : name, appearIn

  • Scala type : String, Id, Int ๋“ฑ

  • ! : ํ•„์ˆ˜ ๊ฐ’ (non-nullable)

  • [ ,] : ๋ฐฐ์—ด (array)

Resolver

  • gql ์ฟผ๋ฆฌ๋ฌธ ํŒŒ์‹ฑ์€ ๋Œ€๋ถ€๋ถ„์˜ gql ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ฒ˜๋ฆฌํ•จ

    • but, data๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๊ตฌ์ฒด์ ์ธ ๊ณผ์ •์€ resolver ๊ฐ€ ๋‹ด๋‹นํ•˜๊ณ , ์ง์ ‘ ๊ตฌํ˜„ํ•ด์•ผ ํ•จ!

  • ๋งŒ์•ฝ field๊ฐ€ ์Šค์นผ๋ผ ๊ฐ’ (๋ฌธ์ž์—ด์ด๋‚˜ ์ˆซ์ž ๊ฐ™์€ primitive type) ์ธ ๊ฒฝ์šฐ ์‹คํ–‰์ด ์ข…๋ฃŒ๋จ

    • ์ฆ‰, ๋” ์ด์ƒ์˜ ์—ฐ์‡„์ ์ธ resolver ํ˜ธ์ถœ์ด ์ผ์–ด๋‚˜์ง€ ์•Š์Œ

Last updated