SlideShare a Scribd company logo
Why UI developers love
GraphQL
Coursera, 9.20.16
A special place in the stack
Right between frontend and backend devs
Backend devs implement the API
GraphQL is an API technology, so it must make sense to backend people:
- Describe data with strong types
- Potential for more efficient responses because of explicit fields
- Easy to refactor backend to microservices
What do you get as a frontend dev?
Speed up your UI development workflow
GraphQL enables next-generation
tools that let you think less about
data fetching.
Think about what data you need,
and it’s there.
How do you query a GraphQL API?
// REST
fetch(`api.server.com/posts/1`).then(...)
// GraphQL - no special tools needed!
fetch(`api.server.com/graphql?
query={ post(id: 1) { title, content } }`).then(...)
Benefits over REST, without special client tools
- Know exactly which fields we are going to get
- Documentation and data exploration built in (something you usually only
get with BaaS!)
- Nested data fetching is trivial
Basic tooling
Realizing the query is more than just a string.
Getting at the query structure
- Tag the query to designate that it’s GraphQL
- Use a simple regex or AST traversal to find
all of the queries
- Alternative: put in .graphql files
Now the GraphQL query is far more than a “magic
string” -- it’s a semantic unit of data fetching
const query = gql`
query HumanQuery {
human(id: "1000") {
name
height(unit: FOOT)
}
}
`;
Static query validation and analysis
Without running the UI:
- Typos in fields
- Wrong arguments
- Deprecated fields
- Identify field usage
apollostack/eslint-plugin-graphql
In-editor autocomplete
- Today: in IntelliJ
- Tomorrow: everywhere
with the upcoming
GraphQL language
service
jimkyndemeyer/js-graphql-intellij-plugin
It’s super easy to build new tools
GraphQL.js: Facebook’s GraphQL tools platform, includes parsing, validation,
traversal, etc: graphql/graphql-js
GraphQL AST: Super nice to work with, matches up with the spec 1:1, you can
use AST explorer: astexplorer.net
Introspection: Every GraphQL server is required to provide info in a standard
format that works with all tools: graphql.org/learn/introspection/
Caching clients
Using the query structure on the client at runtime.
Relay
How might we cache REST?
1. Use URL as cache key
fetchOrLoadFromCache(`/posts/1`)
2. Write custom normalizer for Redux: decompose responses into objects, store
them in separate fields. Might need to handle different endpoints manually,
depending on your API design.
Caching GraphQL: Easier or harder?
Using URLs or queries isn’t great:
fetchOrLoadFromCache(`/graphql?query={...}`)
But we gain much more potential: A fancy query structure that tells us exactly what
fields we’re looking for.
Example: Overlapping queries
query bigQuery {
post(id: 1) {
title, content
author { name, age }
}
}
query smallQuery {
post(id: 1) {
title, content
}
}
Easy to prefetch data and get subsets of previous queries.
Formalize as paths
What’s the atom of GraphQL data? A leaf field.
post(id: 1) -> title // bigQuery, smallQuery
post(id: 1) -> content // bigQuery, smallQuery
post(id: 1) -> author -> name // bigQuery
post(id: 1) -> author -> age // bigQuery
Lets us easily reason about the data we have fetched, replaces the URLs from
REST. This is how Apollo Client works out of the box.
Cache consistency
query Sidebar {
postFeed {
title
}
}
query Post {
post(id: 1) {
title
content
}
}
How do we make the title field for the post refer to
one location in the cache?
Cache consistency
postFeed[0] -> title -> 'Original title'
post(id: 1) -> title -> 'New title'
How do we make the title field for the post refer to
one location in the cache?
Defining cache IDs for the client
Could be server-side like Relay or client-side like Apollo
(obj) => obj.__typename + ':' + obj.id
Paths with IDs
Now we can easily keep our cache consistent!
postFeed[0] -> (id: 1)
post(id: 1) -> (id: 1)
(id: 1) -> title -> 'New title'
Data flow
Now that we have a cache, let’s use it!
Updating the store updates the UI
Smart clients execute the queries when the store changes,
keeping your UI consistent
query Sidebar {
postFeed {
title
}
}
Full data loading path
Smart clients execute the queries when the store changes,
keeping your UI consistent
query Sidebar {
postFeed {
title
}
}
Fetcher
query Sidebar {
postFeed {
title
}
}
Normalizer
Updates can come from anywhere
It’s like automated Flux, which takes advantage of the
GraphQL query structure
query Sidebar {
postFeed {
title
}
}
Other
queries
Mutation
results
Subscription
results
Redux
actions
More tools
Today:
- Static code generation and native clients: apollo-ios
- Pub/sub GraphQL subscriptions: graphql-subscriptions
Tomorrow:
- Client-side data
- Cache expiration
- Building your own bespoke clients
Let’s build the future together!

More Related Content

What's hot (20)

PDF
GraphQL
Joel Corrêa
 
PPTX
Taking Control of your Data with GraphQL
Vinci Rufus
 
PDF
GraphQL + relay
Cédric GILLET
 
PPT
Graphql presentation
Vibhor Grover
 
PDF
Performance optimisation with GraphQL
yann_s
 
PPTX
Into to GraphQL
shobot
 
PDF
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Hafiz Ismail
 
PDF
Better APIs with GraphQL
Josh Price
 
PPTX
An intro to GraphQL
valuebound
 
PPTX
GraphQL Introduction
Serge Huber
 
PDF
London React August - GraphQL at The Financial Times - Viktor Charypar
React London Community
 
PPTX
Introduction to GraphQL
Rodrigo Prates
 
PDF
Intro to GraphQL
Rakuten Group, Inc.
 
PDF
GraphQL & Relay
Viacheslav Slinko
 
PDF
GraphQL
Cédric GILLET
 
PDF
Introduction to GraphQL at API days
yann_s
 
PDF
Graphql
Niv Ben David
 
PDF
GraphQL in an Age of REST
Yos Riady
 
PDF
Serverless GraphQL for Product Developers
Sashko Stubailo
 
PDF
React and GraphQL at Stripe
Sashko Stubailo
 
GraphQL
Joel Corrêa
 
Taking Control of your Data with GraphQL
Vinci Rufus
 
GraphQL + relay
Cédric GILLET
 
Graphql presentation
Vibhor Grover
 
Performance optimisation with GraphQL
yann_s
 
Into to GraphQL
shobot
 
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Hafiz Ismail
 
Better APIs with GraphQL
Josh Price
 
An intro to GraphQL
valuebound
 
GraphQL Introduction
Serge Huber
 
London React August - GraphQL at The Financial Times - Viktor Charypar
React London Community
 
Introduction to GraphQL
Rodrigo Prates
 
Intro to GraphQL
Rakuten Group, Inc.
 
GraphQL & Relay
Viacheslav Slinko
 
Introduction to GraphQL at API days
yann_s
 
Graphql
Niv Ben David
 
GraphQL in an Age of REST
Yos Riady
 
Serverless GraphQL for Product Developers
Sashko Stubailo
 
React and GraphQL at Stripe
Sashko Stubailo
 

Similar to Why UI developers love GraphQL (20)

PDF
Graphql usage
Valentin Buryakov
 
PDF
Tutorial: Building a GraphQL API in PHP
Andrew Rota
 
PPTX
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays
 
PDF
Implementing OpenAPI and GraphQL services with gRPC
Tim Burks
 
PDF
iOS Swift application architecture
Romain Rochegude
 
PDF
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
QAware GmbH
 
PDF
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays
 
PPTX
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Getting value from IoT, Integration and Data Analytics
 
PDF
How easy (or hard) it is to monitor your graph ql service performance
Red Hat
 
PDF
Back-end (Flask_AWS)
GDSC UofT Mississauga
 
PDF
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
React Conf Brasil
 
PPTX
Scala Italy 2015 - Hands On ScalaJS
Alberto Paro
 
PPTX
Alberto Paro - Hands on Scala.js
Scala Italy
 
PDF
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
Chetan Khatri
 
PDF
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
François-Guillaume Ribreau
 
PDF
GraphQL the holy contract between client and server
Pavel Chertorogov
 
PDF
Modern APIs with GraphQL
Taikai
 
PDF
Composable Parallel Processing in Apache Spark and Weld
Databricks
 
PDF
API workshop by AWS and 3scale
3scale
 
PDF
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB
 
Graphql usage
Valentin Buryakov
 
Tutorial: Building a GraphQL API in PHP
Andrew Rota
 
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays
 
Implementing OpenAPI and GraphQL services with gRPC
Tim Burks
 
iOS Swift application architecture
Romain Rochegude
 
Your API on Steroids - Retrofitting GraphQL by Code, Cloud Native or Serverless
QAware GmbH
 
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Getting value from IoT, Integration and Data Analytics
 
How easy (or hard) it is to monitor your graph ql service performance
Red Hat
 
Back-end (Flask_AWS)
GDSC UofT Mississauga
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
React Conf Brasil
 
Scala Italy 2015 - Hands On ScalaJS
Alberto Paro
 
Alberto Paro - Hands on Scala.js
Scala Italy
 
PyconZA19-Distributed-workloads-challenges-with-PySpark-and-Airflow
Chetan Khatri
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
François-Guillaume Ribreau
 
GraphQL the holy contract between client and server
Pavel Chertorogov
 
Modern APIs with GraphQL
Taikai
 
Composable Parallel Processing in Apache Spark and Weld
Databricks
 
API workshop by AWS and 3scale
3scale
 
MongoDB.local Berlin: Building a GraphQL API with MongoDB, Prisma and Typescript
MongoDB
 
Ad

Recently uploaded (20)

PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Ad

Why UI developers love GraphQL

  • 1. Why UI developers love GraphQL Coursera, 9.20.16
  • 2. A special place in the stack Right between frontend and backend devs
  • 3. Backend devs implement the API GraphQL is an API technology, so it must make sense to backend people: - Describe data with strong types - Potential for more efficient responses because of explicit fields - Easy to refactor backend to microservices What do you get as a frontend dev?
  • 4. Speed up your UI development workflow GraphQL enables next-generation tools that let you think less about data fetching. Think about what data you need, and it’s there.
  • 5. How do you query a GraphQL API? // REST fetch(`api.server.com/posts/1`).then(...) // GraphQL - no special tools needed! fetch(`api.server.com/graphql? query={ post(id: 1) { title, content } }`).then(...)
  • 6. Benefits over REST, without special client tools - Know exactly which fields we are going to get - Documentation and data exploration built in (something you usually only get with BaaS!) - Nested data fetching is trivial
  • 7. Basic tooling Realizing the query is more than just a string.
  • 8. Getting at the query structure - Tag the query to designate that it’s GraphQL - Use a simple regex or AST traversal to find all of the queries - Alternative: put in .graphql files Now the GraphQL query is far more than a “magic string” -- it’s a semantic unit of data fetching const query = gql` query HumanQuery { human(id: "1000") { name height(unit: FOOT) } } `;
  • 9. Static query validation and analysis Without running the UI: - Typos in fields - Wrong arguments - Deprecated fields - Identify field usage apollostack/eslint-plugin-graphql
  • 10. In-editor autocomplete - Today: in IntelliJ - Tomorrow: everywhere with the upcoming GraphQL language service jimkyndemeyer/js-graphql-intellij-plugin
  • 11. It’s super easy to build new tools GraphQL.js: Facebook’s GraphQL tools platform, includes parsing, validation, traversal, etc: graphql/graphql-js GraphQL AST: Super nice to work with, matches up with the spec 1:1, you can use AST explorer: astexplorer.net Introspection: Every GraphQL server is required to provide info in a standard format that works with all tools: graphql.org/learn/introspection/
  • 12. Caching clients Using the query structure on the client at runtime. Relay
  • 13. How might we cache REST? 1. Use URL as cache key fetchOrLoadFromCache(`/posts/1`) 2. Write custom normalizer for Redux: decompose responses into objects, store them in separate fields. Might need to handle different endpoints manually, depending on your API design.
  • 14. Caching GraphQL: Easier or harder? Using URLs or queries isn’t great: fetchOrLoadFromCache(`/graphql?query={...}`) But we gain much more potential: A fancy query structure that tells us exactly what fields we’re looking for.
  • 15. Example: Overlapping queries query bigQuery { post(id: 1) { title, content author { name, age } } } query smallQuery { post(id: 1) { title, content } } Easy to prefetch data and get subsets of previous queries.
  • 16. Formalize as paths What’s the atom of GraphQL data? A leaf field. post(id: 1) -> title // bigQuery, smallQuery post(id: 1) -> content // bigQuery, smallQuery post(id: 1) -> author -> name // bigQuery post(id: 1) -> author -> age // bigQuery Lets us easily reason about the data we have fetched, replaces the URLs from REST. This is how Apollo Client works out of the box.
  • 17. Cache consistency query Sidebar { postFeed { title } } query Post { post(id: 1) { title content } } How do we make the title field for the post refer to one location in the cache?
  • 18. Cache consistency postFeed[0] -> title -> 'Original title' post(id: 1) -> title -> 'New title' How do we make the title field for the post refer to one location in the cache?
  • 19. Defining cache IDs for the client Could be server-side like Relay or client-side like Apollo (obj) => obj.__typename + ':' + obj.id
  • 20. Paths with IDs Now we can easily keep our cache consistent! postFeed[0] -> (id: 1) post(id: 1) -> (id: 1) (id: 1) -> title -> 'New title'
  • 21. Data flow Now that we have a cache, let’s use it!
  • 22. Updating the store updates the UI Smart clients execute the queries when the store changes, keeping your UI consistent query Sidebar { postFeed { title } }
  • 23. Full data loading path Smart clients execute the queries when the store changes, keeping your UI consistent query Sidebar { postFeed { title } } Fetcher query Sidebar { postFeed { title } } Normalizer
  • 24. Updates can come from anywhere It’s like automated Flux, which takes advantage of the GraphQL query structure query Sidebar { postFeed { title } } Other queries Mutation results Subscription results Redux actions
  • 25. More tools Today: - Static code generation and native clients: apollo-ios - Pub/sub GraphQL subscriptions: graphql-subscriptions Tomorrow: - Client-side data - Cache expiration - Building your own bespoke clients Let’s build the future together!