SlideShare a Scribd company logo
GraphQL over REST.
Sashko Stubailo, @stubailo
Open Source Lead, Apollo
apollographql.com
@apollographql
What’s Apollo?
GraphQL
(huge potential)
You
(have real work to do)
Our mission is to bring the benefits of developing with
GraphQL to you as quickly and easily as possible.
What’s GraphQL?
1. Define a schema for your data 2. Write a query to get the data you need
It’s an API specification that is quickly replacing REST for how people
communicate between their backends and frontends.
What do APIs have to do with React?
It turns out, a lot of what’s complicated in today’s frontend
development involves dealing with APIs and state management.
GraphQL removes complexity from the frontend.
Reducers
Sagas
Optimistic UI
.then
.catch
fetch
Error handling
Polling
Retries
Offline
Normalization
Instead of manipulating data on the client, you get it in
just the shape that you need right away.
Action creators
Apollo Client: GraphQL state management for React
By enabling React developers to simplify their workflow, in the last 2 years Apollo Client has
become the second most popular React state management solution, after only Redux!
And GraphQL + React is only getting better
With new directions like client-side state management, and quick support for cutting-edge technology like
React Async, with Apollo Client GraphQL and React are a match made in heaven.
There’s only one issue left.
To get the most of all this, you need a
GraphQL API.
GraphQL is often presented as a big rewrite, but
you don’t have to do it that way.
To get the main benefits for product development velocity we talked
about above, you don’t need to rethink your architecture.
You can get GraphQL working in just a few hours, and something
running in production in days.
You’ve already got an API.
If you work with React and don’t use GraphQL, you
probably work with a REST API or similar.
You often aren’t able to jump in and make major
changes to the backend when you want.
Even if you could, rewriting all your hard-built
business logic probably isn’t a good idea.
So what’s the solution?
REST REST REST
Complexity
Your app
Put GraphQL over REST.
Put a GraphQL layer in between your existing REST
backends and your React app.
Get all of the benefits of a GraphQL architecture without
modifying your backends.
From the point of view of the REST API, the same calls
will be made as before.
But now, the frontend doesn’t have to format, filter, and
manage the data anymore. REST REST REST
GraphQL API
Same feature, better result, less work
GET /api/sandwich/bread
GET /api/sandwich/meat
GET /api/sandwich/toppings
With REST
Filter down data to what you want
Do waterfall requests for related data and
combine everything together yourself
With GraphQL
query {
sandwich {
bread { baguette }
meat { turkey }
toppings { avocado, tomato }
}
}
● Same REST API calls
● No roundtrips from the client
● No manual data reformatting and management
● Only get the fields you need - reduce bandwidth
usage and increase performance
A case study with sandwiches.
Article published by Medium
literally yesterday:
GraphQL is changing
the game.
We talk to companies using GraphQL in
production every day, and some teams
tell us they can ship features fully
twice as fast as before.
That more than makes up for the effort of
getting that new API up and running.
Without
GraphQL
With
GraphQL
Existence of
GraphQL
Development
Velocity
2x
1x
OK, so where do I start?
Answer: With the schema.
Describe the API you
wish you had.
Design it based on the needs of your UI, but
try to make it general purpose enough to
evolve.
We’ve found that teams are most successful
when the GraphQL API is designed primarily
by the frontend developers that will use it.
Upcoming events
Justin Timberlake
@jtimberlake
Beyoncé
@beyonce
Man of the Woods tour
April 29, 2018
Man of the Woods tour
June 14, 2018
Man of the Woods tour
July 30, 2018
Coming up with part of our schema
Upcoming events
Justin Timberlake
@jtimberlake
Beyoncé
@beyonce
Man of the Woods tour
April 29, 2018
Man of the Woods tour
June 14, 2018
Man of the Woods tour
July 30, 2018
Using graphql-tools to
implement the schema
github.com/apollographql/graphql-tools
graphql-tools makes it easy to create a
production-ready GraphQL schema using the
schema language.
Nostalgia: It’s one of the first libraries we’ve
ever published and today most GraphQL
servers use it!
Testing it out via mocking
Some GraphQL schema design tips
Use field parameters for different
versions of the same field,
something you can’t easily do with
REST!
For ultimate future-proofing, use
globally unique IDs to avoid
depending on a specific backend.
Stick to simple fields over general
purpose fields that take complex
queries. This makes your API
easier to test and refactor.
posts(
searchQuery: String
sort: SortOptions
authorId: String
tags: [String]
)
searchPosts(
query: String
)
query {
post(id: “asdf”) {
title
postedAt(
format: “mm/dd/yyyy”
)
}
}
# Don’t use SQL ids directly
post(id: 5)
# Have an abstracted ID
post(
id: “1224845c-4582”
)
Now, fill in the data.
It’s just like filling in the blanks.
GraphQL API
types and
fields
REST API
endpoints
Every GraphQL schema
field is a function.
You can think of a GraphQL schema as a web of tiny
endpoints, and a query is a way of calling a bunch of
them in one request.
The function that implements a field is called a
resolver, and it can do basically anything.
Resolvers give GraphQL the flexibility of being a
general-purpose API layer.
Your GraphQL resolvers can
call your REST backend.
We can take the REST data fetches from the
client, and move them into the server.
This organizes all our REST API calls in one
place, removing data management
complexity from the client.
Partially mocked data
Real artist information
from the API.
Fake “Hello World” fields
from the mock.
Let’s finish it up.
Let’s take a partially implemented
schema, and add a resolver to call
one more endpoint.
Now, with a single GraphQL
query, we can retrieve data that
used to take two endpoint fetches
in a single request.
Fully API-driven data
Visualizing execution with Apollo Tracing + Engine
Tips when wrapping a REST API with GraphQL
If your REST API has permissions,
just pass through your header
from the GraphQL request to the
underlying REST API.
The performance bar is that your
new GraphQL API doesn’t make
more REST calls than the
equivalent view did in React.
When you’re starting, build just
enough data for one view of your
app with one query.
DB REST API
REST API
Going to production
What do we need from our
production GraphQL?
Deploy and run just like any Node server. Tip: we found
many teams already have this for server-side rendering.
Performance monitoring is important to make sure UI
doesn’t slow over time.
Dataloader per-request caching will help reduce load on
your REST backend.
GraphQL result caching for commonly viewed data can
make some queries nearly instant.
REST REST REST
GraphQL API
Deployment
You can run a GraphQL server anywhere
you can run Node, for example Heroku,
or Zeit Now.
If you’re talking to your REST backends
from the GraphQL API, you probably
want to run the new API in the same
region for faster roundtrips.
Check out the article on the Apollo Blog.
Monitoring GraphQL
Since current APM tools are often built around endpoints,
you’ll need to put in a little extra effort to identify the
performance of different chunks of data.
We recommend using meaningful query and mutation names,
and organizing your stats using those.
Apollo Engine is a tool/service we provide that sets this up for
you, and lets you browse data in a GraphQL-specific way.
apollographql.com/engine
Dataloader
For cases where a single query would request the same resource multiple times, Dataloader can help you
collapse them into one request by identifying the duplicates during execution.
github.com/facebook/dataloader
GraphQL result caching
Just like with REST API calls, you can cache the entire
GraphQL result on a TTL, based on the query.
There are a lot of ways you can set it up, but with the
Apollo cacheControl extension and Apollo Engine, you
can specify the cache expiration right in the schema.
TL;DR tips for GraphQL over REST
1. Design the GraphQL schema you want based on frontend needs
2. Fill in your schema with data from your existing REST endpoints
3. Optimize until you have the same number of fetches you used to do
from the frontend
Above all, do it fast, since it could make a huge difference in how long it
takes to iterate on features.
GraphQL over REST.
Sashko Stubailo, @stubailo
Open Source Lead, Apollo
apollographql.com
@apollographql
<Query query={GET_TODOS}>
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
return data.todos.map(({ id, type }) => (
<p key={id}>{type}</p>
));
}}
</Query>
Breaking news
The new React API for Apollo Client shipped
today, with the new Query component!
dev-blog.apollodata.com

More Related Content

What's hot

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
Sashko Stubailo
 
Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
Rafael Wilber Kerr
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
Cédric GILLET
 
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
Vinci Rufus
 
Graphql
GraphqlGraphql
Graphql
Niv Ben David
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQL
shobot
 
GraphQL
GraphQLGraphQL
GraphQL
Joel Corrêa
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
Tomasz Bak
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
Serge 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 tools
Sashko Stubailo
 
GraphQL London January 2018: Graphql tooling
GraphQL London January 2018: Graphql toolingGraphQL London January 2018: Graphql tooling
GraphQL London January 2018: Graphql tooling
Søren Bramer Schmidt
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
Tomasz Bak
 
GraphQL & Relay
GraphQL & RelayGraphQL & Relay
GraphQL & Relay
Viacheslav Slinko
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
Rodrigo Prates
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
Squareboat
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part Deux
Brad Pillow
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
Virbhadra Ankalkote
 
Intro to GraphQL
 Intro to GraphQL Intro to GraphQL
Intro to GraphQL
Rakuten Group, Inc.
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
bobo52310
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
Muhilvarnan V
 

What's hot (20)

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 Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)Graphql Intro (Tutorial and Example)
Graphql Intro (Tutorial and Example)
 
GraphQL + relay
GraphQL + relayGraphQL + relay
GraphQL + relay
 
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
 
Graphql
GraphqlGraphql
Graphql
 
Into to GraphQL
Into to GraphQLInto to GraphQL
Into to GraphQL
 
GraphQL
GraphQLGraphQL
GraphQL
 
How to GraphQL: React Apollo
How to GraphQL: React ApolloHow to GraphQL: React Apollo
How to GraphQL: React Apollo
 
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
 
GraphQL London January 2018: Graphql tooling
GraphQL London January 2018: Graphql toolingGraphQL London January 2018: Graphql tooling
GraphQL London January 2018: Graphql tooling
 
How to GraphQL
How to GraphQLHow to GraphQL
How to GraphQL
 
GraphQL & Relay
GraphQL & RelayGraphQL & Relay
GraphQL & Relay
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQL
 
GraphQL With Relay Part Deux
GraphQL With Relay Part DeuxGraphQL With Relay Part Deux
GraphQL With Relay Part Deux
 
GraphQL Fundamentals
GraphQL FundamentalsGraphQL Fundamentals
GraphQL Fundamentals
 
Intro to GraphQL
 Intro to GraphQL Intro to GraphQL
Intro to GraphQL
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Introduction to graphQL
Introduction to graphQLIntroduction to graphQL
Introduction to graphQL
 

Similar to GraphQL over REST at Reactathon 2018

Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
Vibhor Grover
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJSCreate GraphQL server with apolloJS
Create GraphQL server with apolloJS
Jonathan Jalouzot
 
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
Red Hat
 
Build the API you want to see in the world
Build the API you want to see in the worldBuild the API you want to see in the world
Build the API you want to see in the world
Michelle Garrett
 
Scaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphScaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with Dgraph
Karthic Rao
 
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
React Conf Brasil
 
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Codemotion
 
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Codemotion
 
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays
 
React Flux to GraphQL
React Flux to GraphQLReact Flux to GraphQL
React Flux to GraphQL
Turadg Aleahmad
 
How to use apolloJS on React ?
How to use apolloJS on React ?How to use apolloJS on React ?
How to use apolloJS on React ?
Jonathan Jalouzot
 
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
Pavel Chertorogov
 
Scaling Your Team With GraphQL: Why Relationships Matter
Scaling Your Team With GraphQL: Why Relationships MatterScaling Your Team With GraphQL: Why Relationships Matter
Scaling Your Team With GraphQL: Why Relationships Matter
Joel Bowen
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Boot
vipin kumar
 
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
Soham Dasgupta
 
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
Rob Crowley
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
Knoldus Inc.
 
How has netflix embraced graph ql for rapid application development
How has netflix embraced graph ql for rapid application developmentHow has netflix embraced graph ql for rapid application development
How has netflix embraced graph ql for rapid application development
jenniferCarnel1
 
apidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Rao
apidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Raoapidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Rao
apidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Rao
apidays
 

Similar to GraphQL over REST at Reactathon 2018 (20)

Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJSCreate GraphQL server with apolloJS
Create GraphQL server with apolloJS
 
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
 
Build the API you want to see in the world
Build the API you want to see in the worldBuild the API you want to see in the world
Build the API you want to see in the world
 
Scaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with DgraphScaling your GraphQL applications with Dgraph
Scaling your GraphQL applications with Dgraph
 
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
 
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
 
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
Michelle Garrett - Build the API you want to see in the world (with GraphQL) ...
 
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
apidays LIVE Australia 2020 - Have your cake and eat it too: GraphQL? REST? W...
 
React Flux to GraphQL
React Flux to GraphQLReact Flux to GraphQL
React Flux to GraphQL
 
How to use apolloJS on React ?
How to use apolloJS on React ?How to use apolloJS on React ?
How to use apolloJS on React ?
 
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
React, GraphQL и Relay - вполне себе нормальный компонентный подход (nodkz)
 
Scaling Your Team With GraphQL: Why Relationships Matter
Scaling Your Team With GraphQL: Why Relationships MatterScaling Your Team With GraphQL: Why Relationships Matter
Scaling Your Team With GraphQL: Why Relationships Matter
 
GraphQL Introduction with Spring Boot
GraphQL Introduction with Spring BootGraphQL Introduction with Spring Boot
GraphQL Introduction with Spring Boot
 
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
 
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
apidays LIVE Hong Kong 2021 - GraphQL : Beyond APIs, graph your enterprise by...
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
How has netflix embraced graph ql for rapid application development
How has netflix embraced graph ql for rapid application developmentHow has netflix embraced graph ql for rapid application development
How has netflix embraced graph ql for rapid application development
 
apidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Rao
apidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Raoapidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Rao
apidays LIVE Paris - The Rise of GraphQL for database APIs by Karthic Rao
 

Recently uploaded

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

GraphQL over REST at Reactathon 2018

  • 1. GraphQL over REST. Sashko Stubailo, @stubailo Open Source Lead, Apollo apollographql.com @apollographql
  • 2. What’s Apollo? GraphQL (huge potential) You (have real work to do) Our mission is to bring the benefits of developing with GraphQL to you as quickly and easily as possible.
  • 3. What’s GraphQL? 1. Define a schema for your data 2. Write a query to get the data you need It’s an API specification that is quickly replacing REST for how people communicate between their backends and frontends.
  • 4. What do APIs have to do with React? It turns out, a lot of what’s complicated in today’s frontend development involves dealing with APIs and state management.
  • 5. GraphQL removes complexity from the frontend. Reducers Sagas Optimistic UI .then .catch fetch Error handling Polling Retries Offline Normalization Instead of manipulating data on the client, you get it in just the shape that you need right away. Action creators
  • 6. Apollo Client: GraphQL state management for React By enabling React developers to simplify their workflow, in the last 2 years Apollo Client has become the second most popular React state management solution, after only Redux!
  • 7. And GraphQL + React is only getting better With new directions like client-side state management, and quick support for cutting-edge technology like React Async, with Apollo Client GraphQL and React are a match made in heaven.
  • 8. There’s only one issue left. To get the most of all this, you need a GraphQL API.
  • 9. GraphQL is often presented as a big rewrite, but you don’t have to do it that way. To get the main benefits for product development velocity we talked about above, you don’t need to rethink your architecture. You can get GraphQL working in just a few hours, and something running in production in days.
  • 10. You’ve already got an API. If you work with React and don’t use GraphQL, you probably work with a REST API or similar. You often aren’t able to jump in and make major changes to the backend when you want. Even if you could, rewriting all your hard-built business logic probably isn’t a good idea. So what’s the solution? REST REST REST Complexity Your app
  • 11. Put GraphQL over REST. Put a GraphQL layer in between your existing REST backends and your React app. Get all of the benefits of a GraphQL architecture without modifying your backends. From the point of view of the REST API, the same calls will be made as before. But now, the frontend doesn’t have to format, filter, and manage the data anymore. REST REST REST GraphQL API
  • 12. Same feature, better result, less work GET /api/sandwich/bread GET /api/sandwich/meat GET /api/sandwich/toppings With REST Filter down data to what you want Do waterfall requests for related data and combine everything together yourself With GraphQL query { sandwich { bread { baguette } meat { turkey } toppings { avocado, tomato } } } ● Same REST API calls ● No roundtrips from the client ● No manual data reformatting and management ● Only get the fields you need - reduce bandwidth usage and increase performance A case study with sandwiches.
  • 13. Article published by Medium literally yesterday:
  • 14. GraphQL is changing the game. We talk to companies using GraphQL in production every day, and some teams tell us they can ship features fully twice as fast as before. That more than makes up for the effort of getting that new API up and running. Without GraphQL With GraphQL Existence of GraphQL Development Velocity 2x 1x
  • 15. OK, so where do I start? Answer: With the schema.
  • 16. Describe the API you wish you had. Design it based on the needs of your UI, but try to make it general purpose enough to evolve. We’ve found that teams are most successful when the GraphQL API is designed primarily by the frontend developers that will use it. Upcoming events Justin Timberlake @jtimberlake Beyoncé @beyonce Man of the Woods tour April 29, 2018 Man of the Woods tour June 14, 2018 Man of the Woods tour July 30, 2018
  • 17. Coming up with part of our schema Upcoming events Justin Timberlake @jtimberlake Beyoncé @beyonce Man of the Woods tour April 29, 2018 Man of the Woods tour June 14, 2018 Man of the Woods tour July 30, 2018
  • 18. Using graphql-tools to implement the schema github.com/apollographql/graphql-tools graphql-tools makes it easy to create a production-ready GraphQL schema using the schema language. Nostalgia: It’s one of the first libraries we’ve ever published and today most GraphQL servers use it!
  • 19. Testing it out via mocking
  • 20. Some GraphQL schema design tips Use field parameters for different versions of the same field, something you can’t easily do with REST! For ultimate future-proofing, use globally unique IDs to avoid depending on a specific backend. Stick to simple fields over general purpose fields that take complex queries. This makes your API easier to test and refactor. posts( searchQuery: String sort: SortOptions authorId: String tags: [String] ) searchPosts( query: String ) query { post(id: “asdf”) { title postedAt( format: “mm/dd/yyyy” ) } } # Don’t use SQL ids directly post(id: 5) # Have an abstracted ID post( id: “1224845c-4582” )
  • 21. Now, fill in the data.
  • 22. It’s just like filling in the blanks. GraphQL API types and fields REST API endpoints
  • 23. Every GraphQL schema field is a function. You can think of a GraphQL schema as a web of tiny endpoints, and a query is a way of calling a bunch of them in one request. The function that implements a field is called a resolver, and it can do basically anything. Resolvers give GraphQL the flexibility of being a general-purpose API layer.
  • 24. Your GraphQL resolvers can call your REST backend. We can take the REST data fetches from the client, and move them into the server. This organizes all our REST API calls in one place, removing data management complexity from the client.
  • 25. Partially mocked data Real artist information from the API. Fake “Hello World” fields from the mock.
  • 26. Let’s finish it up. Let’s take a partially implemented schema, and add a resolver to call one more endpoint. Now, with a single GraphQL query, we can retrieve data that used to take two endpoint fetches in a single request.
  • 28. Visualizing execution with Apollo Tracing + Engine
  • 29. Tips when wrapping a REST API with GraphQL If your REST API has permissions, just pass through your header from the GraphQL request to the underlying REST API. The performance bar is that your new GraphQL API doesn’t make more REST calls than the equivalent view did in React. When you’re starting, build just enough data for one view of your app with one query. DB REST API REST API
  • 31. What do we need from our production GraphQL? Deploy and run just like any Node server. Tip: we found many teams already have this for server-side rendering. Performance monitoring is important to make sure UI doesn’t slow over time. Dataloader per-request caching will help reduce load on your REST backend. GraphQL result caching for commonly viewed data can make some queries nearly instant. REST REST REST GraphQL API
  • 32. Deployment You can run a GraphQL server anywhere you can run Node, for example Heroku, or Zeit Now. If you’re talking to your REST backends from the GraphQL API, you probably want to run the new API in the same region for faster roundtrips. Check out the article on the Apollo Blog.
  • 33. Monitoring GraphQL Since current APM tools are often built around endpoints, you’ll need to put in a little extra effort to identify the performance of different chunks of data. We recommend using meaningful query and mutation names, and organizing your stats using those. Apollo Engine is a tool/service we provide that sets this up for you, and lets you browse data in a GraphQL-specific way. apollographql.com/engine
  • 34. Dataloader For cases where a single query would request the same resource multiple times, Dataloader can help you collapse them into one request by identifying the duplicates during execution. github.com/facebook/dataloader
  • 35. GraphQL result caching Just like with REST API calls, you can cache the entire GraphQL result on a TTL, based on the query. There are a lot of ways you can set it up, but with the Apollo cacheControl extension and Apollo Engine, you can specify the cache expiration right in the schema.
  • 36. TL;DR tips for GraphQL over REST 1. Design the GraphQL schema you want based on frontend needs 2. Fill in your schema with data from your existing REST endpoints 3. Optimize until you have the same number of fetches you used to do from the frontend Above all, do it fast, since it could make a huge difference in how long it takes to iterate on features.
  • 37. GraphQL over REST. Sashko Stubailo, @stubailo Open Source Lead, Apollo apollographql.com @apollographql <Query query={GET_TODOS}> {({ loading, error, data }) => { if (loading) return <p>Loading...</p>; if (error) return <p>Error :(</p>; return data.todos.map(({ id, type }) => ( <p key={id}>{type}</p> )); }} </Query> Breaking news The new React API for Apollo Client shipped today, with the new Query component! dev-blog.apollodata.com