Beginners Guide to GraphQL
GraphQL
Why?
It was 1984 2011.
Facebook had recently launched their mobile app on iOS as well as Android.
They had a vision of reusing lot of Facebook’s already existing code. ( Write once, Run Anywhere )
Data Services
Web Server
Web Browser
Native App
HTML
Mobile Apps of Facebook were just the Web Browsers wrapped in a Native Frame. (Web View)
Issues 😓
The Native Architecture
Data Services
App Services
Native App
Data
Issues with RESTful API and FQL ( Facebook’s SQL-like API )
Visualisation of Data
Overfetching / Underfetching of Data
GET /usr/info
Returns pretty much everything.
{
name: “John Doe”,
username: “jdoe123”,
age: 31,
gender: “M”,
country: “India”,
Profession: “Programmer”
}
Overfetching / Underfetching of Data
More issues
Client
Server
REST
Endpoints
Client
Server
GraphQL
Endpoints
The Native Architecture with GraphQL
Data Services
App Services
Native App
What is GraphQL?
REQUEST
{
me{
name
}
}
RESPONSE
{
me{
name: “Siddhant”
}
}
Server
Important Concepts
https://www.howtographql.com/basics/2-core-concepts/
Wait..but why is GraphQL
GraphQL??
Any ideas? Graph Databases? Anyone?
GraphQL operates on App Data Graph
When we write any application, we generally operate on set of objects and these objects are connected in certain capacities.
The relationships between these objects form an App Data Graph.
And, GraphQL allows us to extract trees from the app data graph.
Yes, GraphQL allows us to extract trees from the app data graph.
Example: A library Application
Let’s run a query
query {
book(isbn: "9780674430006") {
title
authors {
name
}
}
}
{
book: {
title: “Capital in the Twenty First Century”,
authors: [
{ name: ‘Thomas Piketty’ },
{ name: ‘Arthur Goldhammer’ },
]
}
}
Extracting data from App Graph
And Here’s the tree
Benefits
No more Over and Underfetching
Rapid Product Iterations on the Frontend
App Server
Client
This data shape please!
Here’s your data
Insightful Analytics on the Backend
A Schema & Type System
Being used by many giant organizations
Open Source. Try to help out.
When to use GraphQL?🤔
References
Looking for the How? Let the coding begin 💻🔥
GSoC & Outreachy Meetup
Next Tuesday
Join the Community
@osdcjiit
#jiit-lug on Freenode
github.com/osdc
telegram.me/jiitosdc