SlideShare a Scribd company logo
with Reason
Incremental Type Safety
in React Apollo
Evans Hauser
Core Developer, Apollo
Apollo Project 🚀
import React from 'react';
import { render } from 'react-dom';
import ApolloClient from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';
import App from ‘./App';
const client = new ApolloClient({
uri: ‘https://localhost:3010/graphql'
});
const ApolloApp = () => (
<ApolloProvider client={client}>
<App />
</ApolloProvider>
);
render(ApolloApp, document.getElementById('root'));)
index.js
import FreeJobPost from “./FreeJobPost.js”

import PromotedPost from “./PromotedPost.js”
…
render() {
...
<FreeJobPost info={info1} />
<FreeJobPost info={info2} />
<FreeJobPost info={info3} />
<PromotedPost info={info4} />
...
}
App.js Adding to the 🚀
What about Reason 🤔
npm install bs-platform
npm install reason-react
{
"name": “package-name",
"sources": {
"dir": "src",
"subdirs": [“components"],
},
"reason": {
"react-jsx": 2
},
"refmt": 3
}
bsconfig.json
How to add Reason to your 🚀
Build: bsb -make-world
Watch: bsb -make-world -w
import PromotedPost from “./PromotedPost.bs.js”
render() {
...
<FreeJobPost info={info1} />
<FreeJobPost info={info2} />
<FreeJobPost info={info3} />
<PromotedPost info={info4} />
...
}
App.js Inside the 🚀
let component =
ReasonReact.statelessComponent(“PromotedPost”);
let make = (~info, _children) => {
...component,
render: (self) =>
<div>
<Post text=info.text timeLeft=info.timeLeft />
</div>
};
let default =
ReasonReact.wrapReasonForJs(
~component,
(props) => make(~info=settingsInfoFromJs(props##info), [||])
);
PromotedPost.re Adding Reason
PromotedPost.re Adding Reason
let component =
ReasonReact.statelessComponent(“PromotedPost”);
let make = (~info, _children) => {
...component,
render: (self) =>
<div>
<Post text=info.text timeLeft=info.timeLeft />
</div>
};
let default =
ReasonReact.wrapReasonForJs(
~component,
(props) => make(~info=settingsInfoFromJs(props##info), [||])
);
PromotedPost.re Adding Reason
let component =
ReasonReact.statelessComponent(“PromotedPost”);
let make = (~info, _children) => {
...component,
render: (self) =>
<div>
<Post text=info.text timeLeft=info.timeLeft />
</div>
};
let default =
ReasonReact.wrapReasonForJs(
~component,
(props) => make(~info=settingsInfoFromJs(props##info), [||])
);
let component =
ReasonReact.statelessComponent(“Post”);
let make = (~text, ~timeLeft, _children) => {
…component,
render: (self) =>
<input
_type=“checkbox”
value=text
checked=(text > 0)
/>
};
Post.re Reason Subcomponent
Reason FTW
Strong Typing 💪
let component =
ReasonReact.statelessComponent(“Post”);
let make = (~text, ~timeLeft, _children) => {
…component,
render: (self) =>
<input
_type=“checkbox”
value=text
checked=(timeLeft > 0)
/>
};
Post.re Reason Subcomponent
Pitfall
🎉 JS Interop 🎉
let component =
ReasonReact.statelessComponent(“Post”);
let make = (~text, ~timeLeft, _children) => {
…component,
render: (self) =>
<input
_type=“checkbox”
value=text
checked=(Js.Boolean.to_js_boolean(timeLeft > 0))
/>
};
Post.re Javascript Interop
PromotedPost.re Adding Reason
let component =
ReasonReact.statelessComponent(“PromotedPost”);
let make = (~info, _children) => {
...component,
render: (self) =>
<div>
<Post text=info.text timeLeft=info.timeLeft />
</div>
};
let default =
ReasonReact.wrapReasonForJs(
~component,
(props) => make(~info=settingsInfoFromJs(props##info), [||])
);
PromotedPost.re More Interop
let component =
ReasonReact.statelessComponent(“PromotedPost”);
let make = (~info, _children) => {
...component,
render: (self) =>
<div>
<p>Promoted Posting:</p>
<Post text=info.text timeLeft=info.timeLeft />
</div>
};
let default =
ReasonReact.wrapReasonForJs(
~component,
(props) => make(~info=settingsInfoFromJs(props##info), [||])
);
type postInfo = {.
“text”: string,
“timeLeft”: number
};
let postInfoFromJs = (jsInfo : postInfo) => {
text: jsInfo##text,
timeLeft: jsInfo##timeLeft
};
const examplePosting = {
“text”: “description of posting”,
“timeLeft”: 200
};
Defining TypesPromotedPost.re
App.js
What about GraphQL 🤔
Typed Query Language
Strong Reason support
Creating separation through GraphQL
npm install graphql_ppx
npm install reason_apollo
{
"bs-dependencies": [
"reason-react",
“reason-apollo"
],
"ppx-flags": [
"./node_modules/graphql_ppx/ppx -ast-out"
],
}
bsconfig.json
Adding GraphQL to your 🚀
Separation through GraphQL
module PromotedPostQuery = [%graphql {|
query getPromotedPosts {
info {
text
timeLeft
}
}
|}];
let promotedPosts = PromotedPostQuery.make(());
GqlPost.re
Separation through GraphQL
let component = ReasonReact.statelessComponent("PromotedPost");
[@bs.module "react-apollo"] external gql: 'a =>
[@bs] ReasonReact.reactClass => ReasonReact.reactClass = "graphql";
let wrap = (gql (promotedPosts##query));
let default =
[@bs] wrap (ReasonReact.wrapReasonForJs(
~component,
(props : {..
"data": {..
"data": TodosQuery.t,
"loading": Js.boolean,
}
}) => make(~result=props, [||])
)
));
GqlPost.re
Separation through GraphQL
let make = (~result, _children) => {
...component,
render: (self) =>
if(Js.to_bool (result##data##loading)){
<div> <String text="Loading"/> </div>
} else {
let text = result##data##info##text;
let timeLeft = result##data##info##timeLeft;
<div>
<Post text=text timeLeft=timeLeft />
</div>
}
};
GqlPost.re
A Possible API
module PromotedPostQuery = [%graphql {|
query getPromotedPosts {
info {
text
timeLeft
}
}
|}];
let make = (~result, _children) => {
...component,
render: (self) =>
if(Js.to_bool (result##loading)){
<div> <String text="Loading"/> </div>
} else {
let text = result##data##info##text;
let timeLeft = result##data##info##timeLeft;
<div>
<Post text=info.text timeLeft=info.timeLeft />
</div>
}
};
let default = ReasonApollo.graphql (PromotedPostsQuery) {"PromotedPost", make);
Let’s collaborate!
Evans Hauser
@evanshauser
evans@apollograpql.com
• Next Steps:
• Ensure that your types work
across the client server
boundary
• Manage client-side state with
apollo-link-state
Huge thank you to Ben Souci for his
help putting together this talk!

More Related Content

What's hot (20)

Getting Started-with-Laravel
Getting Started-with-LaravelGetting Started-with-Laravel
Getting Started-with-Laravel
Mindfire Solutions
 
Me and my importers
Me and my importersMe and my importers
Me and my importers
Donny Wals
 
Phing101 or How to staff a build orchestra
Phing101 or How to staff a build orchestraPhing101 or How to staff a build orchestra
Phing101 or How to staff a build orchestra
raphaelstolt
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
DEVCON
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
DEVCON
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applications
Tim Cull
 
JavaScript Testing for Rubyists
JavaScript Testing for RubyistsJavaScript Testing for Rubyists
JavaScript Testing for Rubyists
Jamie Dyer
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
Andréia Bohner
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Complex Sites with Silex
Complex Sites with SilexComplex Sites with Silex
Complex Sites with Silex
Chris Tankersley
 
Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
Luca Mearelli
 
Crafting [Better] API Clients
Crafting [Better] API ClientsCrafting [Better] API Clients
Crafting [Better] API Clients
Wellfire Interactive
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
Michael Peacock
 
21.search in laravel
21.search in laravel21.search in laravel
21.search in laravel
Razvan Raducanu, PhD
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
Chris Love
 
JavaCro'15 - Remote controlling Parrot AR Drone with Spring Boot and Vaadin -...
JavaCro'15 - Remote controlling Parrot AR Drone with Spring Boot and Vaadin -...JavaCro'15 - Remote controlling Parrot AR Drone with Spring Boot and Vaadin -...
JavaCro'15 - Remote controlling Parrot AR Drone with Spring Boot and Vaadin -...
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
How to develop modern web application framework
How to develop modern web application frameworkHow to develop modern web application framework
How to develop modern web application framework
techmemo
 
Powershell function
Powershell functionPowershell function
Powershell function
LearningTech
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
techmemo
 
Me and my importers
Me and my importersMe and my importers
Me and my importers
Donny Wals
 
Phing101 or How to staff a build orchestra
Phing101 or How to staff a build orchestraPhing101 or How to staff a build orchestra
Phing101 or How to staff a build orchestra
raphaelstolt
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
DEVCON
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
DEVCON
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applications
Tim Cull
 
JavaScript Testing for Rubyists
JavaScript Testing for RubyistsJavaScript Testing for Rubyists
JavaScript Testing for Rubyists
Jamie Dyer
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5Алексей Плеханов: Новинки Laravel 5
Алексей Плеханов: Новинки Laravel 5
Oleg Poludnenko
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
Luca Mearelli
 
Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012Dealing with Continuous Data Processing, ConFoo 2012
Dealing with Continuous Data Processing, ConFoo 2012
Michael Peacock
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
Chris Love
 
How to develop modern web application framework
How to develop modern web application frameworkHow to develop modern web application framework
How to develop modern web application framework
techmemo
 
Powershell function
Powershell functionPowershell function
Powershell function
LearningTech
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
techmemo
 

Similar to Incremental Type Safety in React Apollo (20)

Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
DeepAnshu Sharma
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
Nidhi Chauhan
 
Dpilot - Source Code with Snapshots
Dpilot - Source Code with SnapshotsDpilot - Source Code with Snapshots
Dpilot - Source Code with Snapshots
Kritika Phulli
 
React render props
React render propsReact render props
React render props
Saikat Samanta
 
Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
Nitish Phanse
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
Fernando Daciuk
 
Nevermore Unit Testing
Nevermore Unit TestingNevermore Unit Testing
Nevermore Unit Testing
Ihsan Fauzi Rahman
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
Abdul Malik Ikhsan
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기
NAVER SHOPPING
 
React lecture
React lectureReact lecture
React lecture
Christoffer Noring
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
joshcjensen
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Codemotion
 
React outbox
React outboxReact outbox
React outbox
Angela Lehru
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
t k
 
React 101
React 101React 101
React 101
Casear Chu
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
Christoffer Noring
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk "Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
Fwdays
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
DeepAnshu Sharma
 
Source Code for Dpilot
Source Code for Dpilot Source Code for Dpilot
Source Code for Dpilot
Nidhi Chauhan
 
Dpilot - Source Code with Snapshots
Dpilot - Source Code with SnapshotsDpilot - Source Code with Snapshots
Dpilot - Source Code with Snapshots
Kritika Phulli
 
Higher Order Components and Render Props
Higher Order Components and Render PropsHigher Order Components and Render Props
Higher Order Components and Render Props
Nitish Phanse
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
Fernando Daciuk
 
Codeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept ImplementationCodeigniter : Two Step View - Concept Implementation
Codeigniter : Two Step View - Concept Implementation
Abdul Malik Ikhsan
 
Angular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.xAngular 1.x vs. Angular 2.x
Angular 1.x vs. Angular 2.x
Eyal Vardi
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기
NAVER SHOPPING
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
joshcjensen
 
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Codemotion
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
t k
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Luciano Mammino
 
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk "Use Component Drivers to Control Components in Tests", Roman Shevchuk
"Use Component Drivers to Control Components in Tests", Roman Shevchuk
Fwdays
 

Recently uploaded (20)

Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Data Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptxData Structures_Searching and Sorting.pptx
Data Structures_Searching and Sorting.pptx
RushaliDeshmukh2
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)International Journal of Distributed and Parallel systems (IJDPS)
International Journal of Distributed and Parallel systems (IJDPS)
samueljackson3773
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Raish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdfRaish Khanji GTU 8th sem Internship Report.pdf
Raish Khanji GTU 8th sem Internship Report.pdf
RaishKhanji
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 

Incremental Type Safety in React Apollo

  • 1. with Reason Incremental Type Safety in React Apollo Evans Hauser Core Developer, Apollo
  • 2. Apollo Project 🚀 import React from 'react'; import { render } from 'react-dom'; import ApolloClient from 'apollo-boost'; import { ApolloProvider } from 'react-apollo'; import App from ‘./App'; const client = new ApolloClient({ uri: ‘https://localhost:3010/graphql' }); const ApolloApp = () => ( <ApolloProvider client={client}> <App /> </ApolloProvider> ); render(ApolloApp, document.getElementById('root'));) index.js
  • 3. import FreeJobPost from “./FreeJobPost.js”
 import PromotedPost from “./PromotedPost.js” … render() { ... <FreeJobPost info={info1} /> <FreeJobPost info={info2} /> <FreeJobPost info={info3} /> <PromotedPost info={info4} /> ... } App.js Adding to the 🚀
  • 5. npm install bs-platform npm install reason-react { "name": “package-name", "sources": { "dir": "src", "subdirs": [“components"], }, "reason": { "react-jsx": 2 }, "refmt": 3 } bsconfig.json How to add Reason to your 🚀 Build: bsb -make-world Watch: bsb -make-world -w
  • 6. import PromotedPost from “./PromotedPost.bs.js” render() { ... <FreeJobPost info={info1} /> <FreeJobPost info={info2} /> <FreeJobPost info={info3} /> <PromotedPost info={info4} /> ... } App.js Inside the 🚀
  • 7. let component = ReasonReact.statelessComponent(“PromotedPost”); let make = (~info, _children) => { ...component, render: (self) => <div> <Post text=info.text timeLeft=info.timeLeft /> </div> }; let default = ReasonReact.wrapReasonForJs( ~component, (props) => make(~info=settingsInfoFromJs(props##info), [||]) ); PromotedPost.re Adding Reason
  • 8. PromotedPost.re Adding Reason let component = ReasonReact.statelessComponent(“PromotedPost”); let make = (~info, _children) => { ...component, render: (self) => <div> <Post text=info.text timeLeft=info.timeLeft /> </div> }; let default = ReasonReact.wrapReasonForJs( ~component, (props) => make(~info=settingsInfoFromJs(props##info), [||]) );
  • 9. PromotedPost.re Adding Reason let component = ReasonReact.statelessComponent(“PromotedPost”); let make = (~info, _children) => { ...component, render: (self) => <div> <Post text=info.text timeLeft=info.timeLeft /> </div> }; let default = ReasonReact.wrapReasonForJs( ~component, (props) => make(~info=settingsInfoFromJs(props##info), [||]) );
  • 10. let component = ReasonReact.statelessComponent(“Post”); let make = (~text, ~timeLeft, _children) => { …component, render: (self) => <input _type=“checkbox” value=text checked=(text > 0) /> }; Post.re Reason Subcomponent
  • 12. let component = ReasonReact.statelessComponent(“Post”); let make = (~text, ~timeLeft, _children) => { …component, render: (self) => <input _type=“checkbox” value=text checked=(timeLeft > 0) /> }; Post.re Reason Subcomponent
  • 14. let component = ReasonReact.statelessComponent(“Post”); let make = (~text, ~timeLeft, _children) => { …component, render: (self) => <input _type=“checkbox” value=text checked=(Js.Boolean.to_js_boolean(timeLeft > 0)) /> }; Post.re Javascript Interop
  • 15. PromotedPost.re Adding Reason let component = ReasonReact.statelessComponent(“PromotedPost”); let make = (~info, _children) => { ...component, render: (self) => <div> <Post text=info.text timeLeft=info.timeLeft /> </div> }; let default = ReasonReact.wrapReasonForJs( ~component, (props) => make(~info=settingsInfoFromJs(props##info), [||]) );
  • 16. PromotedPost.re More Interop let component = ReasonReact.statelessComponent(“PromotedPost”); let make = (~info, _children) => { ...component, render: (self) => <div> <p>Promoted Posting:</p> <Post text=info.text timeLeft=info.timeLeft /> </div> }; let default = ReasonReact.wrapReasonForJs( ~component, (props) => make(~info=settingsInfoFromJs(props##info), [||]) );
  • 17. type postInfo = {. “text”: string, “timeLeft”: number }; let postInfoFromJs = (jsInfo : postInfo) => { text: jsInfo##text, timeLeft: jsInfo##timeLeft }; const examplePosting = { “text”: “description of posting”, “timeLeft”: 200 }; Defining TypesPromotedPost.re App.js
  • 18. What about GraphQL 🤔 Typed Query Language Strong Reason support
  • 20. npm install graphql_ppx npm install reason_apollo { "bs-dependencies": [ "reason-react", “reason-apollo" ], "ppx-flags": [ "./node_modules/graphql_ppx/ppx -ast-out" ], } bsconfig.json Adding GraphQL to your 🚀
  • 21. Separation through GraphQL module PromotedPostQuery = [%graphql {| query getPromotedPosts { info { text timeLeft } } |}]; let promotedPosts = PromotedPostQuery.make(()); GqlPost.re
  • 22. Separation through GraphQL let component = ReasonReact.statelessComponent("PromotedPost"); [@bs.module "react-apollo"] external gql: 'a => [@bs] ReasonReact.reactClass => ReasonReact.reactClass = "graphql"; let wrap = (gql (promotedPosts##query)); let default = [@bs] wrap (ReasonReact.wrapReasonForJs( ~component, (props : {.. "data": {.. "data": TodosQuery.t, "loading": Js.boolean, } }) => make(~result=props, [||]) ) )); GqlPost.re
  • 23. Separation through GraphQL let make = (~result, _children) => { ...component, render: (self) => if(Js.to_bool (result##data##loading)){ <div> <String text="Loading"/> </div> } else { let text = result##data##info##text; let timeLeft = result##data##info##timeLeft; <div> <Post text=text timeLeft=timeLeft /> </div> } }; GqlPost.re
  • 24. A Possible API module PromotedPostQuery = [%graphql {| query getPromotedPosts { info { text timeLeft } } |}]; let make = (~result, _children) => { ...component, render: (self) => if(Js.to_bool (result##loading)){ <div> <String text="Loading"/> </div> } else { let text = result##data##info##text; let timeLeft = result##data##info##timeLeft; <div> <Post text=info.text timeLeft=info.timeLeft /> </div> } }; let default = ReasonApollo.graphql (PromotedPostsQuery) {"PromotedPost", make);
  • 25. Let’s collaborate! Evans Hauser @evanshauser [email protected] Next Steps: • Ensure that your types work across the client server boundary • Manage client-side state with apollo-link-state Huge thank you to Ben Souci for his help putting together this talk!