SlideShare a Scribd company logo
1 of 33
July 2018 | Confidential
Redux vs. GraphQL
Lessons learned by Jordon McKoy
● Review of Redux
● Review of GraphQL
● Apollo Client
● Code Example
Lesson Plan
Learning
Outcomes
● What is GraphQL and why should I
care about it?
● How can GraphQL help me build
apps?
● Can I replace Redux in my apps
with Apollo Client and GraphQL?
5
Redux Review
Redux is a predictable state container for JavaScript apps.
… It helps you write applications that behave consistently,
run in different environments (client, server, and native),
and are easy to test.
– redux.js.org
“
”
What is Redux?
6
Redux Data Flow
7
What problems does Redux solve?
✓ Knowing what part of state changed
✓ Subscribing to state changes
Redux Review
8
What’s so great about it?
✓ Predictable
✓ Single source of truth
✓ Testable
✓ Ecosystem
Redux Review
9
What’s not so great?
Redux Review
11
GraphQL Review
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.org/learn
“
”
What is GraphQL?
13
ServerSchemaClient
Data
Uses resolver
recipes
14
15
16
Client
GraphQL
Server
SQL Database
NoSQL
Database
Third-party API
Express server
17
What problems does GraphQL solve?
✓ Multiple client round trips
✓ Bloated REST responses
GraphQL Review
18
What’s so great about it?
✓ Declarative
✓ Self documenting
✓ Nested queries
✓ Works across the stack
GraphQL Review
19
What’s not so great?
✓ Schema and resolver definition
✓ Not faster than REST*
GraphQL Review
21
Server
Runtime
Client
Data binding
Engine
Gateway
Apollo Platform
22
Why use Apollo?
✓ Provides data binding
✓ Caching + Pagination
✓ Incrementally adoptable
Apollo Client
23
There are only two hard things in Computer Science: cache
invalidation and naming things.
– Phil Karlton
“
”
https://martinfowler.com/bliki/TwoHardThings.html
24
Apollo Client Data Flow
25
26
Apollo Link
27
Call REST endpoints inside client queries with apollo-
link-rest
✓ No GraphQL server needed
✓ Data managed by Apollo client
✓ Great for prototyping
Apollo Client
28
Manage state through the local cache with apollo-link-
state
✓ Direct access to the cache
✓ Combine local and remote data
Apollo Client
29
Apollo Client Data Flow
30
Apollo Client Data Flow
Redux Apollo Client
Dispatch Action Make Query/Mutation
Reducer & store update
Automatic normalization & cache
update
Store Cache
31
✓ Data - external api
✓ Communication - status
✓ Control - forms + UI state
✓ Session - user data + permissions
✓ Location - localization
Now where do I manage state?
32
GenericComponent
Apollo Client
✓ Provide a query for the Query component to fetch
✓ Response is passed to child component using render prop API
✓ Communication state - loading and error props also passed
33
Lesson Plan
✓ Review of Redux
✓ Review of GraphQL
✓ Apollo Client
✓ Code Example
✓ What is GraphQL and why should I care about it?
✓ How can GraphQL help me build apps?
✓ Can I replace Redux in my apps with Apollo Client
and GraphQL?
Learning Outcomes
34
Lesson Plan
✓ Review of Redux
✓ Review of GraphQL
✓ Apollo Client
✓ Code Example
✓ What is GraphQL and why should I care about it?
✓ How can GraphQL help me build apps?
✓ Can I replace Redux in my apps with Apollo Client
and GraphQL?
Learning Outcomes
July 2018 | Confidential
@jMcKoy25
jordonmckoy
Q & A

More Related Content

What's hot

Adding GraphQL to your existing architecture
Adding GraphQL to your existing architectureAdding GraphQL to your existing architecture
Adding GraphQL to your existing architectureSashko Stubailo
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQLSquareboat
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQLMuhilvarnan V
 
Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...
Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...
Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...Flink Forward
 
GraphQL Advanced
GraphQL AdvancedGraphQL Advanced
GraphQL AdvancedLeanIX GmbH
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part DeuxBrad Pillow
 
Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...
Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...
Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...Flink Forward
 
One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)
One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)
One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)GlobalLogic Ukraine
 
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
 
Industrializing Machine learning pipelines
Industrializing Machine learning pipelinesIndustrializing Machine learning pipelines
Industrializing Machine learning pipelinesGermain Tanguy
 
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"Flink Forward
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React ApolloTomasz Bak
 
KliqPlan Overview
KliqPlan OverviewKliqPlan Overview
KliqPlan OverviewKT-Labs
 
Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...
Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...
Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...Flink Forward
 

What's hot (20)

Adding GraphQL to your existing architecture
Adding GraphQL to your existing architectureAdding GraphQL to your existing architecture
Adding GraphQL to your existing architecture
 
Graphql
GraphqlGraphql
Graphql
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
 
GraphQL Search
GraphQL SearchGraphQL Search
GraphQL Search
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
 
Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...
Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...
Flink Forward Berlin 2018: Ravi Suhag & Sumanth Nakshatrithaya - "Managing Fl...
 
GraphQL & Relay
GraphQL & RelayGraphQL & Relay
GraphQL & Relay
 
GraphQL Advanced
GraphQL AdvancedGraphQL Advanced
GraphQL Advanced
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part Deux
 
Graphql
GraphqlGraphql
Graphql
 
Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...
Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...
Flink Forward Berlin 2018: Raj Subramani - "A streaming Quantitative Analytic...
 
One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)
One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)
One More State Management in Angular (NGRX vs. NGXS vs. Akita vs. RXJS)
 
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
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
Industrializing Machine learning pipelines
Industrializing Machine learning pipelinesIndustrializing Machine learning pipelines
Industrializing Machine learning pipelines
 
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
Flink Forward Berlin 2018: Timo Walther - "Flink SQL in Action"
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
 
GraphQL
GraphQLGraphQL
GraphQL
 
KliqPlan Overview
KliqPlan OverviewKliqPlan Overview
KliqPlan Overview
 
Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...
Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...
Flink Forward Berlin 2018: Aljoscha Krettek & Till Rohrmann - Keynote: "A Yea...
 

Similar to Redux vs GraphQL

GraphQL vs. (the) REST
GraphQL vs. (the) RESTGraphQL vs. (the) REST
GraphQL vs. (the) RESTcoliquio GmbH
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at StripeSashko Stubailo
 
PiterPy 2016: Parallelization, Aggregation and Validation of API in Python
PiterPy 2016: Parallelization, Aggregation and Validation of API in PythonPiterPy 2016: Parallelization, Aggregation and Validation of API in Python
PiterPy 2016: Parallelization, Aggregation and Validation of API in PythonMax Klymyshyn
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherReact Conf Brasil
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL StackSashko Stubailo
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherSashko Stubailo
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceRed Hat
 
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud EnvironmentsTools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud EnvironmentsVMware Tanzu
 
Serverless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersServerless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersSashko Stubailo
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJSCreate GraphQL server with apolloJS
Create GraphQL server with apolloJSJonathan Jalouzot
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPAndrew Rota
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018Sashko Stubailo
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsLuis Cruz
 
Intro to JavaScript for APEX Developers
Intro to JavaScript for APEX DevelopersIntro to JavaScript for APEX Developers
Intro to JavaScript for APEX DevelopersDaniel McGhan
 

Similar to Redux vs GraphQL (20)

React Flux to GraphQL
React Flux to GraphQLReact Flux to GraphQL
React Flux to GraphQL
 
GraphQL vs. (the) REST
GraphQL vs. (the) RESTGraphQL vs. (the) REST
GraphQL vs. (the) REST
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
 
PiterPy 2016: Parallelization, Aggregation and Validation of API in Python
PiterPy 2016: Parallelization, Aggregation and Validation of API in PythonPiterPy 2016: Parallelization, Aggregation and Validation of API in Python
PiterPy 2016: Parallelization, Aggregation and Validation of API in Python
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Doc store
Doc storeDoc store
Doc store
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
 
Vue.js Use Cases
Vue.js Use CasesVue.js Use Cases
Vue.js Use Cases
 
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud EnvironmentsTools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
Tools and Recipes to Replatform Monolithic Apps to Modern Cloud Environments
 
Serverless GraphQL for Product Developers
Serverless GraphQL for Product DevelopersServerless GraphQL for Product Developers
Serverless GraphQL for Product Developers
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJSCreate GraphQL server with apolloJS
Create GraphQL server with apolloJS
 
jdays 2015
jdays 2015jdays 2015
jdays 2015
 
Grails 101
Grails 101Grails 101
Grails 101
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018GraphQL over REST at Reactathon 2018
GraphQL over REST at Reactathon 2018
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
 
Intro to JavaScript for APEX Developers
Intro to JavaScript for APEX DevelopersIntro to JavaScript for APEX Developers
Intro to JavaScript for APEX Developers
 

Recently uploaded

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 

Redux vs GraphQL

Editor's Notes

  1. About a month and a half ago I wrote a blog post that you can find on the Rangle website taking a brief look at setting up a graphql server with graphql-yoga. For those that don’t know, graphql-yoga is built on top of apollo-server and while I was procrastinating.. Researching for the post I took a look at apollo client and what I read there lead to the idea for this talk. I’m very excited to talk GraphQL, I find it a very interesting technology due to its implications for not only backend developers or just frontend developers, but all developers no matter what part of the stack they work on. My title is a misleading however. Redux is a side state management library. GraphQL is a query language for APIs and an alternative for REST backends. They solve two different types of problems and a straight up comparison would be silly. They are like apples and oranges, but it’s a little click-baity so I’m not mad about that. GraphQL is a server-focused technology and you don’t need much to make calls to a GraphQL server from React and get data. However, it’s recommended to leverage one of the available open source client libraries like Apollo or Relay. These clients make fetching data relatively simple and come with a bunch of great out of the box features that you won’t need to spend time trying to implement yourself. The Apollo client in particular, has a library that enables us to hook into its cache and use it like a data store. Like we use Redux for its store and state management. So the true comparison, is between Apollo client’s state management potential and Redux.
  2. How many people have used or are using Redux in their React apps? How many people have used or are using GraphQL in their apps before? If you had the ability to use it but chose not to, what were the reasons? “I don’t work on the backend” “No time to refactor”
  3. Redux is a predictable state container for JavaScript apps. … It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test This attributes are important and underline the benefits of Redux
  4. Go over the flow of data in Redux
  5. Knowing what part - Actions keep track of the type of state change and the reducers handle the change. Imagine a fairly sized app using a simple object to keep state. Any part of your application might be able to modify the state object, it’d be very messy to debug when you don’t know when a change was triggered or even where it came from. BONUS: passing values from top of the tree to components lower down without needing to use prop drilling. Don’t need Redux for this and don’t need Redux is this is why you use it, you can use the Context API instead but it’s still a great feature of Redux
  6. Predictable - When I dispatch an action, I know what is going to happen and I can see the effect in my reducer. Often taken for granted and sometimes abused (abstractions over top). There is a tradeoff here we’ll discuss in a bit Single source of truth - A history of changes that enables things like time traveling dev tools and just an easier debugging experience. Testable - Easy to test, testing reducers and actions is straightforward. Actions are just objects you can make assertions against. Because changes are predictable you can test the effect of your reducers after they’ve been run. Great ecosystem - Side effect libraries: Redux Thunk, Observable, Sagas. Number of testing libraries. Redux dev tools
  7. Need to be careful not to mutate state The process - setting up and updating your actions, action types, reducers, selectors, sagas, etc. Context Heavy The time tradeoff here is what grants us the predictability
  8. Developed by Facebook, like React Query language: “a language for the specification of procedures for the retrieval (and sometimes also modification) of information from a database.” like SQL The impression it’s server only, it IS definitely a server first technology but there are ways to use GraphQL as more than that as we’ll see shortly
  9. The query language starts with the schema. You build a schema by defining custom types - models of your data and defining resolvers that tell GraphQL how to produce results when these types are queried. Participation: Missing something, can someone tell me or guess what is missing from these type definitions? (ID field) ** Restaurant meal type - name of meal, price, origin
  10. Restaurant analogy Restaurant is your app logic ( server ) Client is a customer Schema is the menu Server is the chef Resolver is a recipe Making a query = ordering food Basic scalar types: Int, Float, Boolean, String, ID Custom scalar types require you to define how it is serialized, deserialized, and validated
  11. Familiar JSON shape Meal query - who ordered it, name of meal, price : Jerk chicken, Jordon ordered it, 12.99
  12. MUTATION Meal query - who ordered it, name of meal, price : Jerk chicken, Jordon ordered it, 12.99
  13. Calls from client -> GraphQL server -> makes calls to data sources -> data gets sent back down GraphQL server connects multiple data sources and endpoints into one endpoint This encourages teams to move logic around the retrieval and transformation of data from the client to the server. A drawback is the increased load to backend teams. However, frontend teams can now focus on building better user experiences instead of data transformation code. Something like sorting paginated data makes sense to do it on the server anyway, why not have that built once in your server instead of reimplementing code to handle this across all your clients. The client should just be a customer of your app’s restaurant, never in the kitchen with the chef. This helps to build consistency in your app across different environments, values that we saw earlier, were to key to Redux and are key to building GraphQL powered apps
  14. Particularly with REST Multiple client round trips - There is a single endpoint the client makes calls to. This means the client can drastically reduce the amount of traffic from the client to server or third party APIs. Ability to batch queries. This is a big win for mobile clients, reducing network calls not only reduces impact on data Bloated REST responses - Making a REST call at times feels asking someone a simple question and getting their life story as an answer. Fitting with the restaurant analogy, not being able to request modifications to your meal. With GraphQL queries you specify the exact data you want and get no more, no less. Another win for mobile clients where there is more emphasis placed on smaller payloads.
  15. Declarative - Consistent with a query language like SQL and even React, GraphQL queries are declarative. We simply ask for data and GraphQL figures out how best to supply it to us Self documenting - The schema gives you an overview of the surface area your API covers. Developers can study it and get a picture of how data is related and how they can interact with it. Tools like Graphiql (Repl like environment with introspection that allows you to see every query or mutation possible) for your team or the public to experiment with, great for open source projects Nested queries - With REST it’s common to make calls to multiple endpoints to retrieve enough data to build the shape your component needs. With GraphQL you can get all the data your component needs in one call, even if the data lives in different data sources. Eg. If order type data lived in a database and meal type data lived in a third-party api Works all across the stack - Client libraries with native support and multiple server implementations (Ruby, means a consistent way to manage data in all parts of your application stack GraphQL best practices encourage avoiding versioning of your endpoint instead, favouring the continuous evolution of your schema. With REST there can be little control over the data returned (from a client perspective), any change to an endpoint could be considered a potential breaking change. With GraphQL you’re free to add new fields and new type to add functionality. This can be useful for open source projects that find maintaining multiple versions of endpoints a challenge
  16. GraphQL is not a silver bullet, it’s a tool, like Redux, and can be overkill for a project when it’s not truly needed. Developer discretion is always required. Schema and resolver definition - Not only does your schema need to be in defined (what is your data), you need to define resolvers to tell GraphQL how to resolve your queries. (how to find your data). This is another trade off and how GraphQL works to maintain type integrity Can be slower than multiple REST calls - I feel one of the misconceptions surrounding GraphQL (maybe not so much these days) is that it is faster than REST. “I only need to make a single call to a GraphQL endpoint to fetch the same data that used to take 3 calls to a REST endpoint”. Those REST calls didn’t evaporate, they still exist, they’ve just been moved from the client to the server. However, if the calls were against your own database and not from a third party API and you used something like Prisma in front of your database, I can see that definitely being faster than a REST approach.
  17. Foundational libraries in their ecosystem of GraphQL tools Client: Binds data to React Engine: Gateway that adds some features like another cache layer, performance and error tracking Server: Run-time, facilitates the connection of multiple data sources Open source
  18. Works with any GraphQL server When you install Apollo Client, you get caching + pagination out the box. You get options for refetching queries, retrying requests, and polling out of the box as well. Dev tools
  19. Let’s see where the cache fits as data flows through the Apollo client Query is like dispatching action Automatic normalization and caching Subscription of changes
  20. The automatic caching in Apollo client is great. All network responses are normalized, response data is split into individual objects and assigned a unique identifier and typename property, storing them in a flattened structure. Will pull data already loaded in the cache instead of making another network request if possible.
  21. We’ve looked at how Apollo stores data in the cache, how can we possibly use this cache to manage our own state? The answer is with Apollo Links! Apollo Link is a pluggable network interface layer, a system of modular components for GraphQL networking. My mental model is to think of these links like middleware for the Apollo client Error Context Batching Websockets The two I’d like to highlight are apollo-link-state and apollo-link-rest
  22. It’s easy to think of it as a middleware that hooks into the cache. This link is the key to enabling Apollo client as a tool for state management. It exposes functions that allow you to read and write directly to the cache.
  23. The link-state and link-rest add more data sources We can query local cache and rest api the same way as we would a graphql server. Again, consistency in how we interact data Pretty powerful but 2 stores creates a potential problem. They CAN live together, requires a delegation of responsibilities. Keeping both removes a single source of truth 1 stores makes it easier to debug, persist state
  24. Once more, Redux and GraphQL are two very different things. I’m really trying to hammer home how we’re able to use the Apollo Client cache for many of the same things we use Redux for. Comparison when using Redux for data fetching
  25. James K Nelson Data - from external apis Communication - api flight status Control - forms, component/view specific state, filters Session - user data, permissions Location - localization info, usually kept in URL
  26. Before looking at the code examples, I want to introduce and talk about a couple of the components made available through the client. New in the latest version of Apollo Client is the Query component, and the preferred way to declaratively fetch data. You use it by passing a graphql query to it and apollo will fetch your data for you. It uses a render prop API so it will pass the result to its child. This child being your wrapped component. Along with the result, the Query component also passes a loading and error prop that can be used to render different states of your component. The mutation component triggers mutations or changes to your data. It is similar to the query component in that you pass it a graphql mutation but the along side the data, loading, and error props, a function is passed to your child component, allowing you to trigger the mutation based on some user interaction. Both come with great additional options and features, for example, Query component has built it options to manage refetching data and retrying requests, as well as polling out of the box - - - - - - - Single purpose components The query lives with the component - no file switching Personally, I’ve found using the render prop API encourages building components that a single purpose, otherwise the nesting can get out of hand quickly. Pros & Cons. Testing. Number of components to make. It was unfamiliar Apollo exposes a compose function, similar to the compose function from Redux or a library like recompose
  27. Why should I care? - advantages over REST (nested queries and payload size) How can it help me? - Encourages moving lots of logic to backend, smaller client responsibilities. Single purpose components.
  28. Why should I care? - advantages over REST (nested queries and payload size) How can it help me? - Encourages moving lots of logic to backend, smaller client responsibilities. Single purpose components. Can I replace Redux? - For data layer operations, yes you can in the vast majority of cases. But for the rest of state, should you? Keep in mind your tech stack, team competencies, timelines, cost considerations (server cost) etc.