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
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
JJUG CCC 2026 Spring AI時代の開発こそ標準化を武器に! ― 方式・プロセス・プラットフォームの標準化
s27watanabe
2
720
速さだけじゃない! VoidZero ツールが移行先に選ばれる理由
mizdra
PRO
6
750
チームで実践する AI-DLC 思考の軌跡を残すチェックポイント設計
belongadmin
0
2.6k
タクシーアプリ『GO』の実践的データ活用
mot_techtalk
2
150
「コーディング」しない人のための Claude Code 入門 ChatGPT の次の一歩 — 業務に組み込む 育成・共有・自動化
rfdnxbro
2
1.2k
Claude Code×Terraform IaC テンプレート駆動開発
itouhi
1
290
そのPoC、何を検証したつもりでしたか? AIプロダクトの価値検証で陥った落とし穴
techtekt
PRO
0
150
Databricks 月刊サービスアップデート 2026年05月号
tyosi1212
0
210
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
4
1.1k
Platform Engineering as a Product: Criteria for Improvement and Multi-Tenant Design
kumorn5s
0
500
EventBridge Connection
_kensh
4
520
Featured
See All Featured
The Language of Interfaces
destraynor
162
27k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
570
Abbi's Birthday
coloredviolet
2
7.9k
Optimising Largest Contentful Paint
csswizardry
37
3.7k
How to Talk to Developers About Accessibility
jct
2
220
Rails Girls Zürich Keynote
gr2m
96
14k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
210
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
A Soul's Torment
seathinner
6
2.9k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
520
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
160
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.