SlideShare uma empresa Scribd logo
1 de 52
Baixar para ler offline
Introduction to
GraphQL
Or How I Learned to Stop
Worrying about REST APIs
Who Am I
Hafiz Ismail
@sogko on all social media
https://wehavefaces.net
What is this about?
What is this about?
I'll try to convince you that GraphQL helps to address some of
the more common headaches developers faced when building
a REST API -backed application.
Who is this for?
Who is this for?
Developers, developers, developers
Let's start!
Typical architecture of a web application using REST
API
Understanding common issues
that developers face
How?
Let's try to design and build a
REST application together!
Yay!
Goal: A newsfeed SPA
Mobile-first
REST API for data fetching
Designing the REST API
Two resources
- Users
- Posts
POST /posts
GET /posts/1
PUT /posts/1
DELETE /posts/1
...
POST /users
GET /users/1
PUT /users/1
DELETE /users/1
...
Someone said: Let's achieve strict
REST! We can do this!
Let's see what happen
Render newsfeed
GET /posts?limit=10
{
"posts": [
{
"id": 1,
"title": "Hello world!",
"author": 10,
"viewCount": 23,
"likedCount": 3,
"likedBy": [1, 3],
},
...
]
}
-
Great!
Oh wait, we need to get author's
name and avatar URL
Render newsfeed
GET /posts?limit=10
GET /users/10
{
"user": {
"id": 10,
"name": "John Doe",
"nickname": "Johnny",
"age": 23,
"avatar_url": "/avatar/10.jpg"
}
}
-
So we make another request to get the
author for the first post...
Render newsfeed
GET /posts?limit=10
GET /users/10
GET /users/20
{
"user": {
"id": 20,
"name": "Emily Sue",
"nickname": "M",
"age": 25,
"avatar_url": "/avatar/20.jpg"
}
}
Wait, so we have to do a separate
request for each post to get
information for its author?
Hhnnggghhh !
Issue #1: Multiple
round trips
This is no bueno
Issue #1: Multiple round trips
One possible solution:
- A new endpoint /newsfeed
But now you have a singleton REST resource that is too tightly-
coupled to your client UI.
You then tell yourself "it's not that bad. We're still REST-ish."
Eventually, you launch your app with its mobile client and it
went viral! Yay!
New requirement!
Here comes your product
designer with changes
New requirement!
• It has been a year since you first
launch your mobile client, and you
have several versions of the client
out in the wild.
• Your product designer said: "We
need to stop showing the
view_count because of reasons"
• What do you do now?
• Removing the view_count field
from /newsfeed is not an option.
• Older version of your mobile client
depends on it. (What if they crash?
#nilpointerreference)
• So newer version of the mobile
client does not need the
view_count field, but to cater to the
older versions, the /newsfeed still
need to return it.
• What if this keeps happening?
Newer clients would be requesting
data that they essentially don't need
anymore.
• Not that bad when you just start out,
but in the long run, it'll be
something nagging at you
• Sleepless nights are ahead for you.
Issue #2:
Overfetching of data
Issue #2: Overfetching of data
Wouldn't it be nice if there client receives only the data that it
requires and had requested?
One possible way to go about this:
• Endpoint accepts parameter to specify the fields that you
are interested in
Not a bad solution, but yet another thing to worry about.
From a humble SPA to
a full-fledge product
You and your core team have build this complex API
that serves a great purpose.
From a humble SPA to a full-
fledge product
• Your CEO recently announced that he envisions that your
product should have a client for every device / platform
imaginable.
• iOS, Android, OSX, Windows, Linux
• Raspberry Pis, BBC micro:bits
• Cars
• Your mom's toaster
From a humble SPA to a full-
fledge product
• New hires/developers join in.
• How do you quickly allow new developers to study your API
• What resources are available,
• What parameters are accepted
• Which ones are required, which ones are not?
From a humble SPA to a full-
fledge product
• If only you had used Swagger / RAML / API Blueprint when
you started.
• Now you have to invest time/effort into it.
• Or probably you already did, bonus points for you !
Issue #3: Documenting your API
now becomes a thing.
Issue #3: Documenting your API now
becomes a thing.
• More than just writing down the specs in a formal form so
that it can be referenced
• How you allow one to discover and explore your API?
• Big enough concern that some parts of the community has
banded together to create tools for this. (Which is a great
thing, yay open-source)
• But yet another thing for you to worry about.
Had enough?
So how do we proceed from here?
Here's where GraphQL can help
What is GraphQL?
What is GraphQL?
GraphQL is a data query language and runtime designed
and used at Facebook to request and deliver data to mobile
and web apps since 2012
Source: http://graphql.org
What is GraphQL?
What you need to know:
- A GraphQL query is a string interpreted by a server that
returns data in a specified format.
Which format? Another propriety format from FB aye?
What is GraphQL?
Here is an example query and its response:
What is GraphQL?
Here is an example query and its response:
Wait, so how does GraphQL
address the issues previously
raised?
Does it even lift, bruh?
Wait, so how does GraphQL
address the issues previously
raised?
Let me show you
Recap of the issues
Issue #1: Multiple round trips.
Issue #2: Overfetching of data.
Issue #3: Documenting your API now
becomes a thing.
It's demo time!
!
Review of demo
Hope nothing crashes
Review of demo
• How to do a query
• curl
• GraphiQL (https://github.com/graphql/graphiql)
• Uses introspection queries to allow one to explore
API
Review of demo
• Addressed the issues that we had previously raised
1. One query is all your probably need to render your UI
fully
2. Your clients would only get data that it is interested in.
3. Built-in documentation and introspection as part as
Schema definition.
What's next?
What's next?
If you're interested to learn more about GraphQL
- GraphQL : https://graphql.org
- #graphql
- Twitter : https://twitter.com/search?q=graphql
- Medium : https://medium.com/search?q=graphql
- https://wehavefaces.net #shamelessplug
- A couple of introductory articles (Go + GraphQL + Relay)
- More articles coming soon
What's next?
GraphQL libraries for many platforms available
- graphql-js (NodeJS)
- graphql-ruby (Ruby)
- graphene (Python)
- sangria (Scala)
- graphql-go (Go/Golang)
(btdubs, GraphQL is platform agnostic, yay)
The real reason why
I'm here
Not for the money nor fame, but...
Looking for more contributors!
graphql-go
https://github.com/graphql-go/graphql
• 8 months year old baby
• Still at its infancy, but growing fast
• Very pleasant and chill community; constructive discussion
always encouraged.
• Actively looking for more contributors (Currently at 15)
Looking for more contributors!
graphql-go
https://github.com/graphql-go/graphql
Ping me @sogko or @chris-ramon
Or better yet, dive right in and just submit a PR!
Very much encouraged
Thanks for listening
Feel free to come up and say hi
Slides will be up @ https://github.com/sogko/fossasia-2016-graphql-demo

Mais conteúdo relacionado

Mais procurados

GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...luisw19
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQLTomasz Bak
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsSashko Stubailo
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQLMuhilvarnan V
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Rafael Wilber Kerr
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQLAmazon Web Services
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React ApolloTomasz Bak
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservicesMohammed Shaban
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs RESTGreeceJS
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFAmazon Web Services
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL StackSashko Stubailo
 

Mais procurados (20)

GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQL
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
 
GraphQL
GraphQLGraphQL
GraphQL
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SF
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
Graphql
GraphqlGraphql
Graphql
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
 

Destaque

GraphQL Story: Intro To GraphQL
GraphQL Story: Intro To GraphQLGraphQL Story: Intro To GraphQL
GraphQL Story: Intro To GraphQLRiza Fahmi
 
GraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsGraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsSashko Stubailo
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLBrainhub
 
Migration microservices to GraphQL
Migration microservices to GraphQLMigration microservices to GraphQL
Migration microservices to GraphQLRoman Krivtsov
 
Work with V8 memory leaks
Work with V8 memory leaksWork with V8 memory leaks
Work with V8 memory leaksRoman Krivtsov
 
Why UI developers love GraphQL
Why UI developers love GraphQLWhy UI developers love GraphQL
Why UI developers love GraphQLSashko Stubailo
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
You're not alone: A Backend Tech Solution Survey
You're not alone: A Backend Tech Solution SurveyYou're not alone: A Backend Tech Solution Survey
You're not alone: A Backend Tech Solution SurveyPlayFab, Inc.
 
Pacts to the Rescue - Making your microservices play nicely together with Con...
Pacts to the Rescue - Making your microservices play nicely together with Con...Pacts to the Rescue - Making your microservices play nicely together with Con...
Pacts to the Rescue - Making your microservices play nicely together with Con...Beth Skurrie
 
Taking Control of your Data with GraphQL
Taking Control of your Data with GraphQLTaking Control of your Data with GraphQL
Taking Control of your Data with GraphQLVinci Rufus
 
Microservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in PracticeMicroservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in PracticeQaiser Mazhar
 
An Introduction To CQRS
An Introduction To CQRSAn Introduction To CQRS
An Introduction To CQRSNeil Robbins
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part DeuxBrad Pillow
 
Javascript MVVM with Vue.JS
Javascript MVVM with Vue.JSJavascript MVVM with Vue.JS
Javascript MVVM with Vue.JSEueung Mulyana
 
Introduction to GraphQL at API days
Introduction to GraphQL at API daysIntroduction to GraphQL at API days
Introduction to GraphQL at API daysyann_s
 
CQRS & event sourcing in the wild
CQRS & event sourcing in the wildCQRS & event sourcing in the wild
CQRS & event sourcing in the wildMichiel Rook
 

Destaque (20)

GraphQL Story: Intro To GraphQL
GraphQL Story: Intro To GraphQLGraphQL Story: Intro To GraphQL
GraphQL Story: Intro To GraphQL
 
GraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsGraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend Devs
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Migration microservices to GraphQL
Migration microservices to GraphQLMigration microservices to GraphQL
Migration microservices to GraphQL
 
Work with V8 memory leaks
Work with V8 memory leaksWork with V8 memory leaks
Work with V8 memory leaks
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
Why UI developers love GraphQL
Why UI developers love GraphQLWhy UI developers love GraphQL
Why UI developers love GraphQL
 
GraphQL & Relay
GraphQL & RelayGraphQL & Relay
GraphQL & Relay
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
GraphQL 101
GraphQL 101GraphQL 101
GraphQL 101
 
You're not alone: A Backend Tech Solution Survey
You're not alone: A Backend Tech Solution SurveyYou're not alone: A Backend Tech Solution Survey
You're not alone: A Backend Tech Solution Survey
 
Pacts to the Rescue - Making your microservices play nicely together with Con...
Pacts to the Rescue - Making your microservices play nicely together with Con...Pacts to the Rescue - Making your microservices play nicely together with Con...
Pacts to the Rescue - Making your microservices play nicely together with Con...
 
Taking Control of your Data with GraphQL
Taking Control of your Data with GraphQLTaking Control of your Data with GraphQL
Taking Control of your Data with GraphQL
 
Microservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in PracticeMicroservices: Consumer Driven Contracts in Practice
Microservices: Consumer Driven Contracts in Practice
 
An Introduction To CQRS
An Introduction To CQRSAn Introduction To CQRS
An Introduction To CQRS
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part Deux
 
Vue JS Intro
Vue JS IntroVue JS Intro
Vue JS Intro
 
Javascript MVVM with Vue.JS
Javascript MVVM with Vue.JSJavascript MVVM with Vue.JS
Javascript MVVM with Vue.JS
 
Introduction to GraphQL at API days
Introduction to GraphQL at API daysIntroduction to GraphQL at API days
Introduction to GraphQL at API days
 
CQRS & event sourcing in the wild
CQRS & event sourcing in the wildCQRS & event sourcing in the wild
CQRS & event sourcing in the wild
 

Semelhante a Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)

Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias
 
Making operations visible - Nick Gallbreath
Making operations visible - Nick GallbreathMaking operations visible - Nick Gallbreath
Making operations visible - Nick GallbreathDevopsdays
 
Making operations visible - devopsdays tokyo 2013
Making operations visible  - devopsdays tokyo 2013Making operations visible  - devopsdays tokyo 2013
Making operations visible - devopsdays tokyo 2013Nick Galbreath
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for LongevityMuleSoft
 
Adding GraphQL to your existing architecture
Adding GraphQL to your existing architectureAdding GraphQL to your existing architecture
Adding GraphQL to your existing architectureSashko Stubailo
 
System design for Web Application
System design for Web ApplicationSystem design for Web Application
System design for Web ApplicationMichael Choi
 
Dev Learn Handout - Session 604
Dev Learn Handout - Session 604Dev Learn Handout - Session 604
Dev Learn Handout - Session 604Chad Udell
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021Soham Dasgupta
 
APIS for Startups - Running your Business Inside Out
APIS for Startups - Running your Business Inside OutAPIS for Startups - Running your Business Inside Out
APIS for Startups - Running your Business Inside Out3scale
 
Learning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails LaunchLearning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails LaunchThiam Hock Ng
 
Accidental API developer - the 12 month pregnancy to create new API
Accidental API developer - the 12 month pregnancy to create new APIAccidental API developer - the 12 month pregnancy to create new API
Accidental API developer - the 12 month pregnancy to create new APIMarjukka Niinioja
 
Your API Sucks! Why developers hang up and how to stop that.
Your API Sucks! Why developers hang up and how to stop that.Your API Sucks! Why developers hang up and how to stop that.
Your API Sucks! Why developers hang up and how to stop that.Apigee | Google Cloud
 
2020 Top Web Development Trends
2020 Top Web Development Trends2020 Top Web Development Trends
2020 Top Web Development TrendsPencil Agency
 
Maintainable Machine Learning Products
Maintainable Machine Learning ProductsMaintainable Machine Learning Products
Maintainable Machine Learning ProductsAndrew Musselman
 
Neil Perlin - We're Going Mobile! Great! Are We Ready?
Neil Perlin - We're Going Mobile! Great! Are We Ready?Neil Perlin - We're Going Mobile! Great! Are We Ready?
Neil Perlin - We're Going Mobile! Great! Are We Ready?LavaConConference
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018Sashko Stubailo
 
Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...
Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...
Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...apidays
 

Semelhante a Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs) (20)

Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO ForumChris Mathias Presents Advanced API Design Considerations at LA CTO Forum
Chris Mathias Presents Advanced API Design Considerations at LA CTO Forum
 
Making operations visible - Nick Gallbreath
Making operations visible - Nick GallbreathMaking operations visible - Nick Gallbreath
Making operations visible - Nick Gallbreath
 
Making operations visible - devopsdays tokyo 2013
Making operations visible  - devopsdays tokyo 2013Making operations visible  - devopsdays tokyo 2013
Making operations visible - devopsdays tokyo 2013
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
 
Adding GraphQL to your existing architecture
Adding GraphQL to your existing architectureAdding GraphQL to your existing architecture
Adding GraphQL to your existing architecture
 
System design for Web Application
System design for Web ApplicationSystem design for Web Application
System design for Web Application
 
Dev Learn Handout - Session 604
Dev Learn Handout - Session 604Dev Learn Handout - Session 604
Dev Learn Handout - Session 604
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021
 
APIS for Startups - Running your Business Inside Out
APIS for Startups - Running your Business Inside OutAPIS for Startups - Running your Business Inside Out
APIS for Startups - Running your Business Inside Out
 
Learning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails LaunchLearning Web Development with Ruby on Rails Launch
Learning Web Development with Ruby on Rails Launch
 
Accidental API developer - the 12 month pregnancy to create new API
Accidental API developer - the 12 month pregnancy to create new APIAccidental API developer - the 12 month pregnancy to create new API
Accidental API developer - the 12 month pregnancy to create new API
 
Your API Sucks! Why developers hang up and how to stop that.
Your API Sucks! Why developers hang up and how to stop that.Your API Sucks! Why developers hang up and how to stop that.
Your API Sucks! Why developers hang up and how to stop that.
 
Are you ready to adopt GraphQL?
Are you ready to adopt GraphQL?Are you ready to adopt GraphQL?
Are you ready to adopt GraphQL?
 
2020 Top Web Development Trends
2020 Top Web Development Trends2020 Top Web Development Trends
2020 Top Web Development Trends
 
Maintainable Machine Learning Products
Maintainable Machine Learning ProductsMaintainable Machine Learning Products
Maintainable Machine Learning Products
 
Ice dec05-04-wan leung
Ice dec05-04-wan leungIce dec05-04-wan leung
Ice dec05-04-wan leung
 
GraphQL.net
GraphQL.netGraphQL.net
GraphQL.net
 
Neil Perlin - We're Going Mobile! Great! Are We Ready?
Neil Perlin - We're Going Mobile! Great! Are We Ready?Neil Perlin - We're Going Mobile! Great! Are We Ready?
Neil Perlin - We're Going Mobile! Great! Are We Ready?
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
 
Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...
Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...
Apidays Paris 2023 - OpenAPI 3.1 and Spring-Boot 3 - What's New?, Badr Nass L...
 

Último

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)

  • 1. Introduction to GraphQL Or How I Learned to Stop Worrying about REST APIs
  • 3. Hafiz Ismail @sogko on all social media https://wehavefaces.net
  • 4. What is this about?
  • 5. What is this about? I'll try to convince you that GraphQL helps to address some of the more common headaches developers faced when building a REST API -backed application.
  • 6. Who is this for?
  • 7. Who is this for? Developers, developers, developers
  • 9. Typical architecture of a web application using REST API
  • 10. Understanding common issues that developers face How?
  • 11. Let's try to design and build a REST application together! Yay!
  • 12. Goal: A newsfeed SPA Mobile-first REST API for data fetching
  • 13. Designing the REST API Two resources - Users - Posts POST /posts GET /posts/1 PUT /posts/1 DELETE /posts/1 ... POST /users GET /users/1 PUT /users/1 DELETE /users/1 ... Someone said: Let's achieve strict REST! We can do this!
  • 14. Let's see what happen
  • 15. Render newsfeed GET /posts?limit=10 { "posts": [ { "id": 1, "title": "Hello world!", "author": 10, "viewCount": 23, "likedCount": 3, "likedBy": [1, 3], }, ... ] } - Great! Oh wait, we need to get author's name and avatar URL
  • 16. Render newsfeed GET /posts?limit=10 GET /users/10 { "user": { "id": 10, "name": "John Doe", "nickname": "Johnny", "age": 23, "avatar_url": "/avatar/10.jpg" } } - So we make another request to get the author for the first post...
  • 17. Render newsfeed GET /posts?limit=10 GET /users/10 GET /users/20 { "user": { "id": 20, "name": "Emily Sue", "nickname": "M", "age": 25, "avatar_url": "/avatar/20.jpg" } } Wait, so we have to do a separate request for each post to get information for its author? Hhnnggghhh !
  • 18. Issue #1: Multiple round trips This is no bueno
  • 19. Issue #1: Multiple round trips One possible solution: - A new endpoint /newsfeed But now you have a singleton REST resource that is too tightly- coupled to your client UI. You then tell yourself "it's not that bad. We're still REST-ish." Eventually, you launch your app with its mobile client and it went viral! Yay!
  • 20. New requirement! Here comes your product designer with changes
  • 21. New requirement! • It has been a year since you first launch your mobile client, and you have several versions of the client out in the wild. • Your product designer said: "We need to stop showing the view_count because of reasons" • What do you do now?
  • 22. • Removing the view_count field from /newsfeed is not an option. • Older version of your mobile client depends on it. (What if they crash? #nilpointerreference) • So newer version of the mobile client does not need the view_count field, but to cater to the older versions, the /newsfeed still need to return it.
  • 23. • What if this keeps happening? Newer clients would be requesting data that they essentially don't need anymore. • Not that bad when you just start out, but in the long run, it'll be something nagging at you • Sleepless nights are ahead for you.
  • 25. Issue #2: Overfetching of data Wouldn't it be nice if there client receives only the data that it requires and had requested? One possible way to go about this: • Endpoint accepts parameter to specify the fields that you are interested in Not a bad solution, but yet another thing to worry about.
  • 26. From a humble SPA to a full-fledge product You and your core team have build this complex API that serves a great purpose.
  • 27. From a humble SPA to a full- fledge product • Your CEO recently announced that he envisions that your product should have a client for every device / platform imaginable. • iOS, Android, OSX, Windows, Linux • Raspberry Pis, BBC micro:bits • Cars • Your mom's toaster
  • 28. From a humble SPA to a full- fledge product • New hires/developers join in. • How do you quickly allow new developers to study your API • What resources are available, • What parameters are accepted • Which ones are required, which ones are not?
  • 29. From a humble SPA to a full- fledge product • If only you had used Swagger / RAML / API Blueprint when you started. • Now you have to invest time/effort into it. • Or probably you already did, bonus points for you !
  • 30. Issue #3: Documenting your API now becomes a thing.
  • 31. Issue #3: Documenting your API now becomes a thing. • More than just writing down the specs in a formal form so that it can be referenced • How you allow one to discover and explore your API? • Big enough concern that some parts of the community has banded together to create tools for this. (Which is a great thing, yay open-source) • But yet another thing for you to worry about.
  • 32. Had enough? So how do we proceed from here?
  • 35. What is GraphQL? GraphQL is a data query language and runtime designed and used at Facebook to request and deliver data to mobile and web apps since 2012 Source: http://graphql.org
  • 36. What is GraphQL? What you need to know: - A GraphQL query is a string interpreted by a server that returns data in a specified format. Which format? Another propriety format from FB aye?
  • 37. What is GraphQL? Here is an example query and its response:
  • 38. What is GraphQL? Here is an example query and its response:
  • 39. Wait, so how does GraphQL address the issues previously raised? Does it even lift, bruh?
  • 40. Wait, so how does GraphQL address the issues previously raised? Let me show you
  • 41. Recap of the issues Issue #1: Multiple round trips. Issue #2: Overfetching of data. Issue #3: Documenting your API now becomes a thing.
  • 43. Review of demo Hope nothing crashes
  • 44. Review of demo • How to do a query • curl • GraphiQL (https://github.com/graphql/graphiql) • Uses introspection queries to allow one to explore API
  • 45. Review of demo • Addressed the issues that we had previously raised 1. One query is all your probably need to render your UI fully 2. Your clients would only get data that it is interested in. 3. Built-in documentation and introspection as part as Schema definition.
  • 47. What's next? If you're interested to learn more about GraphQL - GraphQL : https://graphql.org - #graphql - Twitter : https://twitter.com/search?q=graphql - Medium : https://medium.com/search?q=graphql - https://wehavefaces.net #shamelessplug - A couple of introductory articles (Go + GraphQL + Relay) - More articles coming soon
  • 48. What's next? GraphQL libraries for many platforms available - graphql-js (NodeJS) - graphql-ruby (Ruby) - graphene (Python) - sangria (Scala) - graphql-go (Go/Golang) (btdubs, GraphQL is platform agnostic, yay)
  • 49. The real reason why I'm here Not for the money nor fame, but...
  • 50. Looking for more contributors! graphql-go https://github.com/graphql-go/graphql • 8 months year old baby • Still at its infancy, but growing fast • Very pleasant and chill community; constructive discussion always encouraged. • Actively looking for more contributors (Currently at 15)
  • 51. Looking for more contributors! graphql-go https://github.com/graphql-go/graphql Ping me @sogko or @chris-ramon Or better yet, dive right in and just submit a PR! Very much encouraged
  • 52. Thanks for listening Feel free to come up and say hi Slides will be up @ https://github.com/sogko/fossasia-2016-graphql-demo