GraphQL : Query Language
GraphQL: A query language for APIs.
GraphQL provides a complete description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
graphql.org
GraphQL 개념잡기
GraphQL은 페이스북에서 만든 쿼리 언어입니다. GrpahQL은 요즘 개발자들 사이에서 자주 입에 오르내리고 있으나, 2019년 7월 기준으로 얼리스테이지(early-stage)임은 분명합니다. 국내에서 GraphQL API를 Open API로 공개한 곳은 드뭅니다. 또한, 해외의 경우, Github 사례(Github v4 GraphQL)를 찾을 수는 있지만, 전반적으로 GraphQL API를 Open API로 공개한 곳은 많지 않습니다. 하지만 등장
tech.kakao.com
GrapgQL을 통해 REST 형식의
over fetching : 필요없는 정보들까지 db에서 가져오는 것
under fetching : 하나를 완성하기 위해 리소스를 여러번 요청하는 것
의 불편함을 해소할수 있다.
What is Over-Fetching or Under-fetching?
I've been playing sometimes with graphQL. Before graphQL, we normally use REST API. Many developers said that graphQL fixes some problems of the REST. (e.g. over-fetching & under-fetching). I
stackoverflow.com
하나의 query로 원하는 정보만을 얻을 수 있다.
github.com
Graphql-yoga 서버(localhost:4000) 실행되면 GraphQL Playground 사용가능
이걸 통해 API 구조는 어떤지, db가 잘 작동하는지 확인 가능
코드예시
//import { GraphQLServer } from 'graphql-yoga'
const { GraphQLServer} = require('graphql-yoga');
// 스키마 정의
const typeDefs = `
type Query {
name : String
}
`
const resolvers = {
Query: {
name: () => "odom"
},
}
const server = new GraphQLServer({ typeDefs,resolvers })
server.start(function () { console.log('Server is running on localhost:4000')})
'IT' 카테고리의 다른 글
GraphQL] 조건에 맞게 API 호출 (0) | 2020.02.23 |
---|---|
GraphQL] 외부 API로 데이터 받아오기 (0) | 2020.02.23 |
데이터 시각화 3] NVD3.js , C3.js (0) | 2020.02.17 |
데이터 시각화2] D3.js (0) | 2020.02.17 |
데이터 시각화1] 차트 만들기 // html (0) | 2020.02.17 |
댓글