SlideShare a Scribd company logo
Exploring
Relay-land
Stefano Masini
@stefanomasini
Relay
• Automatic fetching of data, no more Ajax
• Colocation of queries and code
• Caching
• Good for API mashup
• Why not?
A new beginning
• How to fetch data from the server?
• How to write data to the server?
• How to handle URL routing?
• How to manage application (UI) state?
• How to propagate server push notifications?
Size of libraries
LOC - *.js in github project as of Feb 2016
0 K
20 K
40 K
60 K
80 K
100 K
React Relay GraphQL React

Router
Redux
Popularity of libraries
# stars in github project as of Feb 2016
0 K
8 K
16 K
24 K
32 K
40 K
React Relay GraphQL React

Router
Redux
Stars per Line Of Code
AKA what's the smartest idea out there? :-)
React Relay GraphQL React

Router
Redux
Topics
• How to fetch data from the server?
• How to write data to the server?
• How to handle URL routing?
• How to manage application (UI) state?
• How to propagate server push notifications?
GraphQL
• GOALS:
• Space efficient (on the wire)
• Computationally efficient (server side)
GraphQL
DEMO
GraphQL is a type system
User
Site Site
Project Project Project
User
Type
Site
Type
Project
Type
SitesOfUser
Type
ProjectsOfSite
Type
Edges
Edges
Node
Node
Node
Relay enhanced Type
System
User
Site Site
Project Project Project
User
Type
Site
Type
SitesOfUser
Type
Project
Type
ProjectsOfSite
Type
Relay caching (UI)
User X Site A Project 1 Project 2
Relay cache
React view
Server
Schema
let schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'RootQueryType',
fields: () => ({
node: nodeField,
loggedUser: {
type: UserType,
description: 'The logged user',
resolve: (_, _, {rootValue: {loggedUser}}) => loggedUser,
},
})
}),
});
The User Type
let UserType = new GraphQLObjectType({
name: 'User',
interfaces: [nodeInterface],
fields: () => ({
id: globalIdField('User', user => user.id),
node: nodeField,
sites: {
type: UsersInSiteConnection,
description: 'All sites the logged user has access to',
resolve: (user, args, {rootValue: {db}}) =>
connectionFromPromisedArray(
db.getSitesForAUser(user),
args
),
},
})
});
Querying with REST
User
Site Site
Project Project Project
/user/14/all_my_sites
SELECT *
FROM users
LEFT JOIN sites
LEFT JOIN projects
WHERE ...
GraphQL is like an ORM
User
Site Site
so, beware!
query {
user(userId: "14") {
sites {
...
}
}
}
GraphQL is like an ORM
User
Site Site
Project Project Project
so, beware!
query {
user(userId: "14") {
sites {
projects {
...
}
}
}
}
GraphQL is like an ORM
User
Site Site
Project Project Project
so, beware!
resolve(...)
resolve(...)
SELECT *
FROM sites
WHERE ...
SELECT *
FROM projects
WHERE ...
n x
Topics
• How to fetch data from the server?
• How to write data to the server?
• How to handle URL routing?
• How to manage application (UI) state?
• How to propagate server push notifications?
Mutations
Server
Client
"Fat query"
Topics
• How to fetch data from the server?
• How to write data to the server?
• How to handle URL routing?
• How to manage application (UI) state?
• How to propagate server push notifications?
@relayContainer({
fragments: {
user: () => Relay.QL`
fragment on User {
firstName,
lastName,
}
`,
},
})
class UserFullName extends React.Component {
render() {
return <p>
{this.props.user.firstName} {this.props.user.lastName}
</p>;
}
}
Rendering in Relay
Query Configuration
Relay Container
Rendering in Relay
Component
Rendering in React-Router
/user/14/settings
/ <Application>
user/14 <User>
settings <Settings>
/ Q RC <Application>
user/14 Q RC <User>
Relay + Router NAIVE
/user/14/settings
settings Q RC <Settings>
Smart Root Container
/ RC <Application>
user/14 RC <User>
react-router-relay
/user/14/settings
settings RC <Settings>
Topics
• How to fetch data from the server?
• How to write data to the server?
• How to handle URL routing?
• How to manage application (UI) state?
• How to propagate server push notifications?
Relay + Redux
Relay

data store
Redux

data store
• Site Name
• Projects in a Site
• Dialog (open/close)
• New project form
Edit existing project form
???
Topics
• How to fetch data from the server?
• How to write data to the server?
• How to handle URL routing?
• How to manage application (UI) state?
• How to propagate server push notifications?
Keeping clients in sync
Server
Client
Cache
Client
Cache
Client
Cache
AKA: Live Queries
Subscriptions*
• GraphQL "subscription" operator
• Modeled after "events"
• Client must register/deregister
• Server must fire the right events in the right
places
* yet to come, as of Feb 2016
I like Relay and GraphQL
• Modeling this way is fun
• It Just Makes Sense®
• It scales well
RELAY IS
AWESOME but...
Limitations*
• Poor error handling
• ORM-like, hard to optimize DB access
• Root queries
• Subscriptions
* as of Feb 2016
Relay is COMPLEX
Is you app
COMPLEX too?
YES
Give it a try!
NO
Wanna
learn?
Not today, thanks
Stay with REST
and Redux
YES
Thanks!
@stefanomasini
video and slides

More Related Content

PPTX
The API Journey: GraphQL Specification and Implementation
PPTX
The API Journey: from REST to GraphQL
PPTX
Javantura v3 - Develop the right way with S-CASE – Marin Orlić
PDF
From business requirements to working pipelines with apache airflow
PPTX
Apache Airflow overview
PDF
Airflow presentation
PPT
Operation Migration: Migrating Static Content into Cascade Server with our ne...
PDF
Building GraphQL Servers with Node.JS & Prisma
The API Journey: GraphQL Specification and Implementation
The API Journey: from REST to GraphQL
Javantura v3 - Develop the right way with S-CASE – Marin Orlić
From business requirements to working pipelines with apache airflow
Apache Airflow overview
Airflow presentation
Operation Migration: Migrating Static Content into Cascade Server with our ne...
Building GraphQL Servers with Node.JS & Prisma

What's hot (20)

PPTX
LowlaDB intro March 2015
PDF
Logging in The World of DevOps
PDF
Airflow introduction
PDF
Airflow tutorials hands_on
PDF
Web App Prototypes with Google App Engine
PPTX
Introduction to Ruby Native Extensions and Foreign Function Interface
PDF
Introduction to RethinkDB and Horizon.js
PDF
Sprint 42 review
PDF
Experience with C++11 in ArangoDB
PDF
2016 foss4 g track: developing and implementing spatial etl processes with...
PDF
Sprint 38 review
PDF
GraphQL is actually rest
PDF
Docker for mac & local developer environment optimization
PDF
Orchestrating workflows Apache Airflow on GCP & AWS
PPTX
RethinkDB - the open-source database for the realtime web
PDF
Docker and Fluentd (revised)
PPTX
Serverless GraphQL. AppSync 101
PDF
AIRflow at Scale
PDF
Apache Airflow
PDF
Apache airflow
LowlaDB intro March 2015
Logging in The World of DevOps
Airflow introduction
Airflow tutorials hands_on
Web App Prototypes with Google App Engine
Introduction to Ruby Native Extensions and Foreign Function Interface
Introduction to RethinkDB and Horizon.js
Sprint 42 review
Experience with C++11 in ArangoDB
2016 foss4 g track: developing and implementing spatial etl processes with...
Sprint 38 review
GraphQL is actually rest
Docker for mac & local developer environment optimization
Orchestrating workflows Apache Airflow on GCP & AWS
RethinkDB - the open-source database for the realtime web
Docker and Fluentd (revised)
Serverless GraphQL. AppSync 101
AIRflow at Scale
Apache Airflow
Apache airflow
Ad

Viewers also liked (20)

PPTX
Blind river police department interview questions
PPTX
Québec city police department interview questions
PPTX
Albuquerque police department interview questions
PPTX
Kingston police department interview questions
PPTX
Wrangell police department interview questions
PPTX
Clarksville police department interview questions
PPTX
Intro to Agile for Business
PDF
BVDW / IAB Germany - Leibniz Choco Crunchy
PPTX
Cnh presentation
PPTX
Truro police department interview questions
DOCX
Unintended Consequences of Risk Reporting_GearyJoop Final_1
PDF
Betacam sp bvw50
PPTX
Mirabel police department interview questions
PPTX
Sorular. büşra yandık.
PDF
Презентация продукции Ренза
PPT
Ra lecture - muscles of the face
PPTX
Flora & fauna
PPTX
Family history project 3
PPTX
Competencias con la tecnolog++¼a
PDF
Application Form of M3M Golf Estate
Blind river police department interview questions
Québec city police department interview questions
Albuquerque police department interview questions
Kingston police department interview questions
Wrangell police department interview questions
Clarksville police department interview questions
Intro to Agile for Business
BVDW / IAB Germany - Leibniz Choco Crunchy
Cnh presentation
Truro police department interview questions
Unintended Consequences of Risk Reporting_GearyJoop Final_1
Betacam sp bvw50
Mirabel police department interview questions
Sorular. büşra yandık.
Презентация продукции Ренза
Ra lecture - muscles of the face
Flora & fauna
Family history project 3
Competencias con la tecnolog++¼a
Application Form of M3M Golf Estate
Ad

Similar to Exploring Relay land (20)

PDF
Nick Raienko ''Service-oriented GraphQL''
PPTX
SharePoint REST vs CSOM
PDF
GraphQL in an Age of REST
PPTX
Running Airflow Workflows as ETL Processes on Hadoop
PPTX
Intro to node and mongodb 1
PDF
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
KEY
Wider than rails
PPTX
Evolution of a cloud start up: From C# to Node.js
PDF
How to Contribute to Apache Usergrid
PDF
Graphql usage
PPTX
StrongLoop Overview
PDF
API-Entwicklung bei XING
PPTX
Building production websites with Node.js on the Microsoft stack
PDF
GraphQL the holy contract between client and server
PDF
Domain Driven Design Tactical Patterns
PDF
Introduction to CloudStack API
PPTX
Connecting the Dots: Kong for GraphQL Endpoints
PPTX
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
PPTX
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
PDF
A real-world Relay application in production - Stefano Masini - Codemotion Am...
Nick Raienko ''Service-oriented GraphQL''
SharePoint REST vs CSOM
GraphQL in an Age of REST
Running Airflow Workflows as ETL Processes on Hadoop
Intro to node and mongodb 1
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Wider than rails
Evolution of a cloud start up: From C# to Node.js
How to Contribute to Apache Usergrid
Graphql usage
StrongLoop Overview
API-Entwicklung bei XING
Building production websites with Node.js on the Microsoft stack
GraphQL the holy contract between client and server
Domain Driven Design Tactical Patterns
Introduction to CloudStack API
Connecting the Dots: Kong for GraphQL Endpoints
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
A real-world Relay application in production - Stefano Masini - Codemotion Am...

Recently uploaded (20)

PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Digital Strategies for Manufacturing Companies
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
L1 - Introduction to python Backend.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
System and Network Administraation Chapter 3
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Transform Your Business with a Software ERP System
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
medical staffing services at VALiNTRY
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Introduction to Artificial Intelligence
wealthsignaloriginal-com-DS-text-... (1).pdf
Design an Analysis of Algorithms I-SECS-1021-03
PTS Company Brochure 2025 (1).pdf.......
Digital Strategies for Manufacturing Companies
Operating system designcfffgfgggggggvggggggggg
L1 - Introduction to python Backend.pptx
Understanding Forklifts - TECH EHS Solution
VVF-Customer-Presentation2025-Ver1.9.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Upgrade and Innovation Strategies for SAP ERP Customers
System and Network Administraation Chapter 3
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Navsoft: AI-Powered Business Solutions & Custom Software Development
Transform Your Business with a Software ERP System
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
How to Migrate SBCGlobal Email to Yahoo Easily
medical staffing services at VALiNTRY
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Introduction to Artificial Intelligence

Exploring Relay land

  • 2. Relay • Automatic fetching of data, no more Ajax • Colocation of queries and code • Caching • Good for API mashup • Why not?
  • 3. A new beginning • How to fetch data from the server? • How to write data to the server? • How to handle URL routing? • How to manage application (UI) state? • How to propagate server push notifications?
  • 4. Size of libraries LOC - *.js in github project as of Feb 2016 0 K 20 K 40 K 60 K 80 K 100 K React Relay GraphQL React
 Router Redux
  • 5. Popularity of libraries # stars in github project as of Feb 2016 0 K 8 K 16 K 24 K 32 K 40 K React Relay GraphQL React
 Router Redux
  • 6. Stars per Line Of Code AKA what's the smartest idea out there? :-) React Relay GraphQL React
 Router Redux
  • 7. Topics • How to fetch data from the server? • How to write data to the server? • How to handle URL routing? • How to manage application (UI) state? • How to propagate server push notifications?
  • 8. GraphQL • GOALS: • Space efficient (on the wire) • Computationally efficient (server side)
  • 10. GraphQL is a type system User Site Site Project Project Project User Type Site Type Project Type SitesOfUser Type ProjectsOfSite Type
  • 11. Edges Edges Node Node Node Relay enhanced Type System User Site Site Project Project Project User Type Site Type SitesOfUser Type Project Type ProjectsOfSite Type
  • 12. Relay caching (UI) User X Site A Project 1 Project 2 Relay cache React view Server
  • 13. Schema let schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: 'RootQueryType', fields: () => ({ node: nodeField, loggedUser: { type: UserType, description: 'The logged user', resolve: (_, _, {rootValue: {loggedUser}}) => loggedUser, }, }) }), });
  • 14. The User Type let UserType = new GraphQLObjectType({ name: 'User', interfaces: [nodeInterface], fields: () => ({ id: globalIdField('User', user => user.id), node: nodeField, sites: { type: UsersInSiteConnection, description: 'All sites the logged user has access to', resolve: (user, args, {rootValue: {db}}) => connectionFromPromisedArray( db.getSitesForAUser(user), args ), }, }) });
  • 15. Querying with REST User Site Site Project Project Project /user/14/all_my_sites SELECT * FROM users LEFT JOIN sites LEFT JOIN projects WHERE ...
  • 16. GraphQL is like an ORM User Site Site so, beware! query { user(userId: "14") { sites { ... } } }
  • 17. GraphQL is like an ORM User Site Site Project Project Project so, beware! query { user(userId: "14") { sites { projects { ... } } } }
  • 18. GraphQL is like an ORM User Site Site Project Project Project so, beware! resolve(...) resolve(...) SELECT * FROM sites WHERE ... SELECT * FROM projects WHERE ... n x
  • 19. Topics • How to fetch data from the server? • How to write data to the server? • How to handle URL routing? • How to manage application (UI) state? • How to propagate server push notifications?
  • 21. Topics • How to fetch data from the server? • How to write data to the server? • How to handle URL routing? • How to manage application (UI) state? • How to propagate server push notifications?
  • 22. @relayContainer({ fragments: { user: () => Relay.QL` fragment on User { firstName, lastName, } `, }, }) class UserFullName extends React.Component { render() { return <p> {this.props.user.firstName} {this.props.user.lastName} </p>; } } Rendering in Relay
  • 24. Rendering in React-Router /user/14/settings / <Application> user/14 <User> settings <Settings>
  • 25. / Q RC <Application> user/14 Q RC <User> Relay + Router NAIVE /user/14/settings settings Q RC <Settings>
  • 26. Smart Root Container / RC <Application> user/14 RC <User> react-router-relay /user/14/settings settings RC <Settings>
  • 27. Topics • How to fetch data from the server? • How to write data to the server? • How to handle URL routing? • How to manage application (UI) state? • How to propagate server push notifications?
  • 28. Relay + Redux Relay
 data store Redux
 data store • Site Name • Projects in a Site • Dialog (open/close) • New project form Edit existing project form ???
  • 29. Topics • How to fetch data from the server? • How to write data to the server? • How to handle URL routing? • How to manage application (UI) state? • How to propagate server push notifications?
  • 30. Keeping clients in sync Server Client Cache Client Cache Client Cache AKA: Live Queries
  • 31. Subscriptions* • GraphQL "subscription" operator • Modeled after "events" • Client must register/deregister • Server must fire the right events in the right places * yet to come, as of Feb 2016
  • 32. I like Relay and GraphQL • Modeling this way is fun • It Just Makes Sense® • It scales well
  • 34. Limitations* • Poor error handling • ORM-like, hard to optimize DB access • Root queries • Subscriptions * as of Feb 2016
  • 35. Relay is COMPLEX Is you app COMPLEX too? YES Give it a try! NO Wanna learn? Not today, thanks Stay with REST and Redux YES