[WEB]

GraphQL / GraphQL Query / 스키마 설계 / API 만들기

ddgoori 2020. 10. 19. 10:42

velog.io/@ckstn0777/GraphQL-%EC%86%8C%EA%B0%9C

 

GraphQL 소개

GraphQL 은 REST보다 효율적이고 강력하며 유연한 대안을 제공하는 새로운 API 표준입니다.Facebook에서 개발하고 오픈소스 로 개발했으며 현재 전 세계의 대규모 기업 및 개인 커뮤니티에서 관리하고

velog.io

  1. GraphQL 소개
  2. GraphQL Query 기초
  3. GraphQL Query 심화
  4. GraphQL 스키마 설계
  5. [실습] GraphQL API 만들기 - 초기세팅
  6. [실습] GraphQL API 만들기 - 타입간 연결

 

쿼리

{
  person(personID: 1) {
    id
    name
    eyeColor
    gender
    edited
    created
    birthYear
    homeworld{
      name
      orbitalPeriod
    }
  }
}

 

응답

{
  "data": {
    "person": {
      "id": "cGVvcGxlOjE=",
      "name": "Luke Skywalker",
      "eyeColor": "blue",
      "gender": "male",
      "edited": "2014-12-20T21:17:56.891000Z",
      "created": "2014-12-09T13:50:51.644000Z",
      "birthYear": "19BBY",
      "homeworld": {
        "name": "Tatooine",
        "orbitalPeriod": 304
      }
    }
  }
}

 

스키마

"""An individual person or character within the Star Wars universe."""
type Person implements Node {
  """The name of this person."""
  name: String
  """
  The birth year of the person, using the in-universe standard of BBY or ABY -
  Before the Battle of Yavin or After the Battle of Yavin. The Battle of Yavin is
  a battle that occurs at the end of Star Wars episode IV: A New Hope.
  """
  birthYear: String

  """
  The eye color of this person. Will be "unknown" if not known or "n/a" if the
  person does not have an eye.
  """
  eyeColor: String

  """
  The gender of this person. Either "Male", "Female" or "unknown",
  "n/a" if the person does not have a gender.
  """
  gender: String
  """
  The hair color of this person. Will be "unknown" if not known or "n/a" if the
  person does not have hair.
  """
  hairColor: String
  """The height of the person in centimeters."""
  height: Int
  """The mass of the person in kilograms."""
  mass: Float
  """The skin color of this person."""
  skinColor: String
  """A planet that this person was born on or inhabits."""
  homeworld: Planet
  filmConnection(after: String, first: Int, before: String, last: Int): PersonFilmsConnection
  """The species that this person belongs to, or null if unknown."""
  species: Species
  starshipConnection(after: String, first: Int, before: String, last: Int): PersonStarshipsConnection
  vehicleConnection(after: String, first: Int, before: String, last: Int): PersonVehiclesConnection
  """The ISO 8601 date format of the time that this resource was created."""
  created: String
  """The ISO 8601 date format of the time that this resource was edited."""
  edited: String
  """The ID of an object"""
  id: ID!
}

 

"""A connection to a list of items."""
type PersonFilmsConnection {
  """Information to aid in pagination."""
  pageInfo: PageInfo!
  """A list of edges."""
  edges: [PersonFilmsEdge]
  """
  A count of the total number of objects in this connection, ignoring pagination.
  This allows a client to fetch the first five objects by passing "5" as the
  argument to "first", then fetch the total count so it could display "5 of 83",
  for example.
  """
  totalCount: Int
  """
  A list of all of the objects returned in the connection. This is a convenience
  field provided for quickly exploring the API; rather than querying for
  "{ edges { node } }" when no edge data is needed, this field can be be used
  instead. Note that when clients like Relay need to fetch the "cursor" field on
  the edge to enable efficient pagination, this shortcut cannot be used, and the
  full "{ edges { node } }" version should be used instead.
  """
  films: [Film]
}

 

graphql-kr.github.io/learn/schema/

 

GraphQL: API를 위한 쿼리 언어

GraphQL은 API에 있는 데이터에 대한 완벽하고 이해하기 쉬운 설명을 제공하고 클라이언트에게 필요한 것을 정확하게 요청할 수 있는 기능을 제공하며 시간이 지남에 따라 API를 쉽게 진화시키고 ��

graphql-kr.github.io

 

'[WEB]' 카테고리의 다른 글

API 개념  (0) 2021.04.06
효과적인 프로그래밍 공부법  (0) 2020.10.21
하위 .git 폴더 모두 제거  (0) 2020.10.14
깃허브 터미널 사용법  (0) 2020.10.14
WAS/Web Server/Web.xml  (0) 2020.07.15