백성훈 Seonghoon Baek
GraphQL 이란
•API
•Query Language
•Type System
•Schema Definition Language
•Thinking in Graph
•GraphQL Flow
GraphQL이란?
A Collective list of public GraphQLAPIs
Who use GraphQL?
WHAT IS GRAPHQL?
ref: GraphQL.org
“GraphQL is a query language for your API,
and a server-side runtime for executing queries
by using a type system you define for your data”
“GraphQL is a query language for your API,
and a server-side runtime for executing queries
by using a type system you define for your data”
Type SystemQuery LanguageAPI
“GraphQL is a query language for your API,
and a server-side runtime for executing queries
by using a type system you define for your data”
API
API
Web API
Request
Response
Web API
Request
Response
“GraphQL is a query language for your API,
and a server-side runtime for executing queries
by using a type system you define for your data”
Type SystemQuery LanguageAPI
Query Language
{
avatar: ‘….png’,
issue: [
{
id: 1,
content: ‘이슈1’
}
]
}
GraphQL API
Query Language
Server
query
Response
Query Language
Client
profile정보 중에 name, id만 줘
name, id
Query의 기본구조
Query Language
query{
profile(id=“Lutece”) {
name
}
}
query{
Query Name(arg: value) {

field
}
}
Query
{
profile(id=“Lutece”) {
name
}
}
{
data: {
“profile”: {
“name”: “SeonghoonBaek”
}
}
}
Response
Query Language
Query Language
Client Query Server Response
데이터의 응답 형태를 예측할 수 있다.
클라이언트에 최적화된 데이터 형태를 가져올 수 있다.
Query Language
“GraphQL is a query language for your API,
and a server-side runtime for executing queries
by using a type system you define for your data”
Type SystemQuery LanguageAPI
Type System
Type System
Schema Definition Language
데이터의 구조와 데이터간의 관계를 정의하는 방법
Type System
Type System
Query
{
profile(id=“Lutece”) {
name
}
}
Type
type User {
name: String
id: String
}
Type
type Query {
profile(id: String): User
}
Type System
Type (Object)
type User {
name: String
}
Scalar Type
1.INT
2.String
3.Float
4.ID
5.Enum
6.Boolean
Shape
1.list = [INT]
2.interface
3.Union
4.fragment
5.alias
6.! = Non-Null
Type System
Type
type User {
name: String
}
Scalar Type
1.INT
2.String
3.Float
4.ID
5.Enum
6.Boolean
Custom Type
Type System
Query
{
profile(id=“Lutece”) {
name
}
}
Type
type User {
name: String
id: String
}
Type
type Query {
profile(id: String): User
}
응답 데이터의 타입 추론이 가능하다
Type System
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
}
Server
Client
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
{
profile(id=“Lutece”)
{
name
}
}
type Query {
profile(id: String): User
}
Server
Client
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
{
profile(id=“Lutece”)
{
name
}
}
type Query {
profile(id: String): User
}
Server
query
Client
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
{
profile(id=“Lutece”)
{
name
}
}
type Query {
profile(id: String): User
…
}
Server
query
Resolver
Type System
resolver: {
Query: {
profile: (obj, args, context, info){
const profileList = … (from DB, 외부 API..)
return profileList
.find(({ id }) => id === args.id)
},

profiles: () {…}
articles: () {…}
}
}
Resolver
Type System
{
profile(id=“Lutece”) {
name
}
}
Query
resolver: {
Query: {
profile: (obj, args, context, info){
const profileList = … (from DB, 외부 API..)
return profileList
.find(({ id }) => id === args.id)
},

profiles: () {…}
articles: () {…}
}
}
Resolver
Type System
{
profile(id=“Lutece”) {
name
}
}
Query
resolver: {
Query: {
profile: (obj, args, context, info){
const profileList = … (from DB, 외부 API..)
return profileList
.find(({ id }) => id === args.id)
},

profiles: () {…}
articles: () {…}
}
}
Resolver
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
…
}
Type System
Type System
{
profile(id=“Lutece”) {
name
}
}
Query
resolver: {
Query: {
profile: (obj, args, context, info){
const profileList = … (from DB, 외부 API..)
return profileList
.find(({ id }) => id === args.id)
},

profiles: () {…}
articles: () {…}
}
}
Resolver
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
…
}
Type System
Type System
{
profile(id=“Lutece”) {
name
}
}
Query
resolver: {
Query: {
profile: (obj, args, context, info){
const profileList = … (from DB, 외부 API..)
return profileList
.find(({ id }) => id === args.id)
},

profiles: () {…}
articles: () {…}
}
}
Resolver
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
…
}
Type System
{
data: {
“profile”: {
“name”: “SeonghoonBaek”
}
}
}
Client
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
{
profile(id=“Lutece”)
{
name
}
}
type Query {
profile(id: String): User
}
Server
query
Resolver
{
data: {
“profile”: {
“name”: “SeonghoonBaek”
}
}
}
Web API
Github v4 explorer
Thinking in Graphs
Graph
type User {
name: String
id: String
contact: Contact
}
type Contact {
phone: String
home: String
}
Thinking in Graph
Thinking in Graph
Data Graph
추상화
Type
Type
Type
Type
Data Graph
추상화
Type
Type
Type
Type
Tree
Query
data
Thinking in Graph
With GraphQL, you model your business domain as a graph
GraphQL Flow
GraphQL Flow
Resource
Resource
GraphQL Flow
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
}
GraphQL Flow
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
}
GraphQL Flow
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
}
{
profile(id=“Lutece”) {
name
avatar
age
createdAt
}
}
{
profile(id=“Lutece”) {
avatar
name
}
}
GraphQL Flow
type User {
name: String
avatar: Url
age: Int
createdAt: Date
id: String
}
type Query {
profile(id: String): User
}
{
profile(id=“Lutece”) {
name
avatar
age
createdAt
}
}
{
profile(id=“Lutece”) {
avatar
name
}
}
{
data: {
“profile”: {
“name”: “SeonghoonBaek”
“age” : 29
“avatar” : “https:…”
“createdAt: “19..”
“id”: “123123”
}
}
}
{
data: {
“profile”: {
“name”: “SeonghoonBaek”
“avatar” : “https:…”
}
}
}
Resolver
감사합니다 .

GraphQL이란?