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
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
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
160
Claude Code 珍プレー好プレー
shinyasaita
0
290
脱金融のフューチャー・デザイン / Future Design Beyond Finance
ks91
PRO
0
140
ゼロをイチにする仕事が終わったあと
smasato
0
310
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
1
3.6k
プロダクトだけじゃない、社内プロセスにおける自動化・省力化ノススメ
kakehashi
PRO
1
2.8k
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
200
『AIに負けない』より『AIと遊ぶ』」〜ワクワクが最強のテスト・QA学習戦略_公開用
odan611
2
520
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
370
SRE依存からの脱却 運用を開 発チームへ移す、 フルサイ クル開 発体制の実践
joooee0000
0
1.9k
Why is RC4 still being used?
tamaiyutaro
0
310
SRE歴2ヶ月でも開発6年の知見を活かして、チームで止まっていた環境改善を前に進めた話
a_ono
1
220
Featured
See All Featured
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
We Have a Design System, Now What?
morganepeng
55
8.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
150
A designer walks into a library…
pauljervisheath
211
24k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
630
Typedesign – Prime Four
hannesfritz
42
3.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
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.