Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
relay
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kazuhito Hokamura
May 31, 2016
Technology
5.4k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
relay
Kazuhito Hokamura
May 31, 2016
More Decks by Kazuhito Hokamura
See All by Kazuhito Hokamura
TypeScriptとGraphQLで実現する 型安全なAPI実装 / TSKaigi 2024
hokaccha
5
5.1k
Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話
hokaccha
0
3.8k
GraphQLの負債と向き合うためにやっていること
hokaccha
2
1.6k
ユビーのアーキテクチャに対する取り組み
hokaccha
1
490
RailsエンジニアのためのNext.js入門
hokaccha
7
22k
Cookpad Summer Internship 2021 Web Frontend
hokaccha
0
7.4k
巨大なモノリシック Rails アプリケーションの マイクロサービス化戦略 / 2019 microservices in cookpad
hokaccha
3
4.1k
巨大なRailsアプリケーションを「普通」にするための取り組み
hokaccha
1
1.1k
Web Frontend Improvement in Cookpad
hokaccha
1
1.2k
Other Decks in Technology
See All in Technology
トークン最適化のためのユーザーストーリー分析 / User Story Analysis for Token Optimization
oomatomo
0
140
AI 不只幫你寫 Code: 當專案從 300 暴增到 1500, 我們如何撐住 DevOps
appleboy
0
290
クラウドファンディング版StackChan 3体(4体)をインタラクティブな体験型作品にして展示もした話 / スタックチャンお誕生日会2026
you
PRO
0
250
WebGIS AI Agentの紹介
_shimizu
0
600
「勝手に広まる」人気 AI エージェントを爆速で作ろう!(AWS Summit Japan 2026講演資料)
minorun365
PRO
10
2.7k
5分でわかる Amazon Connect_20260608
hwangbyeonghun
0
140
本当の”仕事”を手放せる未来が見えた
mu7889yoon
0
200
次世代ランサムウェア対策の考察 / 20260704 Mitsutoshi Matsuo
shift_evolve
PRO
2
420
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
160
「軸足」は 固定しなくていい - 熱量と強みで描く、しなやかなキャリアの形
kakehashi
PRO
1
290
製造現場での生成AIの活用、およびエージェントAIの実装のあり方、AVEVAの取り組み
iotcomjpadmin
0
180
そこにあるから地図ができる~位置を示す"モノ"を愉しむ~ - Interface 2026年6月号GPS特集オフ会 / interface_202606_GPS_offline
sakaik
1
130
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1370
210k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Typedesign – Prime Four
hannesfritz
42
3.1k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
So, you think you're a good person
axbom
PRO
2
2.1k
Fireside Chat
paigeccino
42
4k
A Soul's Torment
seathinner
6
3k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Are puppies a ranking factor?
jonoalderson
1
3.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
220
Transcript
Relay HTML5ͱ͔ษڧձ #65
@hokaccha
Relay
React
GraphQL
react-relay graphql-relay GraphQL Relay Specification
• ϑϧελοΫͳϑϨʔϜϫʔΫ • σʔλͷετΞAPIͷϋϯυϦϯάશ෦Δ • αʔόʔଆͷ༷/࣮·Ͱ͋Δ
GraphQL
GraphQLͱ • Facebook͕։ൃͨ͠ΫΤϦݴޠ • ΫϥΠΞϯτ/αʔόʔؒͷΓऔΓʹΘΕΔ • RESTRPCͱಉ͡ϨΠϠʔ
http://example.com/products/1 { "id": 1, "name": "foo", "description": "..." "image": {
"uri": "http://...", "width": 120, "height": 120 } }
http://example.com/graphql { "product" : { "id": 1, "name": "foo", "description":
"..." "image": { "uri": "http://...", "width": 120, "height": 120 } } } { product(id: 1) { id, name, description, image(size: 120) { uri, width, height } } } 3FRVFTU 3FTQPOTF
• ඞཁͳϑΟʔϧυ͚ͩΛબՄೳ • ωετͨ͠σʔλΛҰൃͰҾ͚Δ • ܕ͕͋Δ • etc..
GraphQL Relay Specification • Global Object Identification • Cursor Connections
• Input Object Mutations
Relay
• DECLARATIVE • COLOCATION • MUTATIONS
DECLARATIVE
ैདྷͷख๏ 1. Πϕϯτ͕τϦΨʔ͞ΕΔ 2. αʔόʔʹϦΫΤετ͢Δ 3. ϨεϙϯεΛݩʹViewΛ࠶ߏங͢Δ
$el.find('.select').on('change', id => { fetch(`/products/${id}`).then(product => { $('.name').text(product.name); $('.description').text(product.description); });
});
ReactΛͬͨ߹ 1. Πϕϯτ͕τϦΨʔ͞ΕΔ 2. αʔόʔʹϦΫΤετ͢Δ 3. ϨεϙϯεͷσʔλΛݩʹstateΛߋ৽͢Δ • ࣗಈͰView͕ߋ৽͞ΕΔ
class AppComponent extends React.Component { handleSelect(id) { fetch(`/products/{id}`).then(product => {
// update state }); } render() { return ( let { name, description } = this.props.app.product; <div> <ProductSelect onChange={id => this.handleSelect(id)} /> <h1>{name}</h1> <div>{description}</div> </div> ); } } ໋ྩత એݴత
RelayΛͬͨ߹ 1. Πϕϯτ͕τϦΨʔ͞ΕΔ 2. ϦΫΤετΛͭ͘ΔͨΊͷΛߋ৽͢Δ • ࣗಈͰϦΫΤετΛૹΔ • ϨεϙϯεͷσʔλΛݩʹstateΛࣗಈͰߋ৽ •
View͕ࣗಈతʹߋ৽͞ΕΔ
class AppComponent extends React.Component { handleSelect(id) { this.props.relay.setVariables({ id });
} render() { let { name, description } = this.props.app.product; return ( // Reactͷྫͱಉ༷ ); } } const AppContainer = Relay.createContainer(AppComponent, { initialVariables: { id: 1 }, fragments: { app: () => Relay.QL` fragment on App { product(id: $id) { name, description } } `, }, }); એݴత
COLOCATION
query BlogApp { post { title body author { name
} comments { body user { name } } } }
<Post> <PostHeader /> <PostBody /> <Comment> <CommentForm /> <CommentList />
</Comment> </Post>
query PostApp { ...post } fragment post on Post {
titlt body author { ...user } comments { ...comment } } fragment comment on Comment { body user { ...user } } fragment user on User { name }
class PostComponent extends React.Component { //... } export default Relay.createContainer(PostComponent,
{ fragments: { post: () => Relay.QL` fragment on Post { id, title, body author { ${Author.getFragment('user')} } comments { ${Comment.getFragment('comment')} } } ` } });
• ίϯϙʔωϯτʹඞཁͳσʔλ͕Ұྎવ • ΫΤϦΛׂͯ͠࠶ར༻Ͱ͖Δ • ඞཁͳσʔλ͚͍͍ͩײ͡ʹϦΫΤετͯ͠ ͘ΕΔ
Relay.QL
Relay.createContainer(PostComponent, { fragments: { post: () => Relay.QL` fragment on
Post { id title body author { ${Author.getFragment('user')} } comments { ${Comment.getFragment('comment')} } } ` } });
None
babelRelayPlugin.js var getbabelRelayPlugin = require('babel-relay-plugin'); var schema = require('../data/schema.json'); module.exports
= getbabelRelayPlugin(schema.data);
type Query { post: Post } type Post { id:
ID! title: String! body: String author: User comments: [Comment] } type Comment { text: String! user: User } type User { name: String! }
• ίϯύΠϧ࣌ʹϦΫΤετͷܕνΣοΫ͕Δ • αʔόʔଆͱͷσʔλͷෆ߹Λ࣮ߦલʹ͛Δ
RelayͷͭΒΈ
• GraphQL/Reactͷ͕ࣝલఏ • babelΛͬͨϏϧυڥඞਢ • React΄ͲγϯϓϧͰͳ͍ • ͪΐͬͱࢼ͚ͩ͢Ͱෑډߴ͍ • ݱ࣌ͰࢿྉࢀߟΞϓϦ͕ઈతʹগͳ͍
Relayͷظ
• ·͞ʹϑϧελοΫͳϑϨʔϜϫʔΫ • ࣍ੈͷRailsʹͳΕΔՄೳੑ͕ඍϨଘɾɾʁ
fin.