You are on page 1of 20

Why GraphQL?

REST
Representational State Transfer

HTTP Request
Data Storage
Web
Client HTTP Response API Database…
Server
Repository

API - Application Programming Interface


Why GraphQL?

REST
What’s really going inside?

HTTP GET
/users/<id>

/users/<id>posts
Client /users/<id>/
{
followers
“user: {
“id”: “rfdklw”
“name”: “Ana”
}
}
Why GraphQL?

REST
What’s really going on inside?

HTTP GET
/users/<id>

/users/<id>posts
Client {
/users/<id>/
“posts: [{
followers
“id”: “norkdfs”
“title”: “GQL Course”
“content”: “Keep
learning…”
}]
}
Why GraphQL?

REST
What’s really going on inside?

HTTP GET
/users/<id>

/users/<id>posts
Client { /users/<id>/
“followers: [{ followers
“id”: “naodoraks”
“name”: “Lwoen”
“about”: “Worker”
}]
}
Why GraphQL?

See a pattern?
Lot’s of unnecessary requests to different endpoints!

HTTP GET
/users/<id>

/users/<id>posts
Client { /users/<id>/
“followers: [{ followers
“id”: “naodoraks”
“name”: “Lwoen”
“about”: “Worker”
}]
}
Why GraphQL?
GraphQL solves this
issue!

query {
User(id: “98ded”) {
name
posts {
title
}
}
}

Client GraphQL
{
“data: {
“User”: {
“name”: “James”
“posts”: [
{
title: “Be great”
}
],
}
}
Why GraphQL?
Facebook Created this
New Data Query
Language
(Graph)QL as a Whole

A B

In Graph Theory, this is called a directed graph.


A B

In Graph Theory, this is called a undirected graph.

Facebook connections
A B

D
E
c

A Network of connections is now established.


User Sibling 2
name
name
age
age

{
User(id:1){
Hobby
name
Query title
startDate
age
User 2
siblings {
name
age id
name
Sibling
name age
age
hobby {
title
….
Query }
}
}
}
Learning Path

Client GraphQL
(Android) server
Learning Path

Client GraphQL
(Android) server
Relationship
User
id
name
age
profession
….
[Hobby]
[Post]

One to many relationship

Hobby
Post
id
id
title
comment
description
userId userId
Mutations

mu·tate
/ˈmyo͞ otāt/
verb

1.change or cause to change in form or


nature. 




Mutations

Queries
+ Mutations

Fetching
&
Modifying
MongoDB

RDBMS MongoDB
(Relational)DBMS

RDBMS

Relational Database Management Systems

Table Rows Columns


(Relational)DBMS

RDBMS

Relational Database Management Systems

Table Rows Columns


MongoDB
MongoDB

Collections = Document 1, Document 1….


{
_id: ObjectId(7df78ad8902c)
title: ‘GraphQL and Android',
description: ‘Should take this course and share',
by: ‘Paulo Dichone and BuildAppsWithpaulo.com’,
url: ‘http://www.buildappswithpaulo.com',
likes: 100,
comments: [
{
user:'user1',
message: 'My first comment',
dateCreated: new Date(2019,1,20,2,15),
like: 0
},
{
user:'user2',
message: 'My second comments',
dateCreated: new Date(2011,1,25,7,45),
like: 5
}
]
}

You might also like