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
探索・可視化・自動化を一本化 Amazon Quickでデータ活用スピードを上げる方法
koheiyoshikawa
0
170
ダッシュボード"開発"について 〜使われるダッシュボードのつくりかた〜
kimichan
0
190
OpenTelemetryにおけるGoのゼロコード・コンパイル時計装について #fukuokago
quiver
0
200
AIコード生成×サプライチェーン攻撃 — PHPが直面する“二重の信頼問題
shinyasaita
0
450
変更し続けられるシステムをどう保つか — AI時代のSSoTという設計原則
kawauso
1
1k
2年前に削除したPHPクラスが、 ある日突然決済をエラーにした
ykagano
1
750
書籍セキュアAPIについて
riiimparm
0
190
「守りたい体験」を渡すだけで E2E を生成させられるようになった話
hinac0
2
1k
AI工学特論: MLOps・継続的評価
asei
4
880
“それは自分の仕事じゃない"を越えて行け
yuukiyo
1
520
Multicaで30個のミニプロジェクトをAIエージェント運用して見えてきたこと
eiei114
1
620
SRENEXT_2026_Chairs__Talks_in_Tamachi.sre.pdf
srenext
1
140
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.2k
Ruling the World: When Life Gets Gamed
codingconduct
0
290
Navigating Weather and Climate Data
rabernat
0
400
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
360
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
Building Applications with DynamoDB
mza
96
7.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.9k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
270
Un-Boring Meetings
codingconduct
0
350
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
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.