Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
そろそろGraphQLの話をしよう
Search
tt
December 20, 2018
Programming
330
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
そろそろGraphQLの話をしよう
GraphQL と Apollo のお話
tt
December 20, 2018
More Decks by tt
See All by tt
戦略的なフロントエンドテストを実施するために
tatsushitoji
0
120
Our favorite Dependency updates has been deprived
tatsushitoji
2
550
try Undux but...
tatsushitoji
0
290
Other Decks in Programming
See All in Programming
Railsバージョンを4倍にした話
optim
0
450
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
1
440
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
280
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
sbt 2.0: takeoff
eed3si9n
0
160
Jetpack Compose Mechanisms
skydoves
3
820
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
180
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
610
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
510
残高管理から台帳サービスへの進化
artoy
1
200
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Rails Girls Zürich Keynote
gr2m
96
14k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
So, you think you're a good person
axbom
PRO
2
2.2k
Practical Orchestrator
shlominoach
192
12k
Building AI with AI
inesmontani
PRO
1
1.3k
Typedesign – Prime Four
hannesfritz
42
3.2k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Design in an AI World
tapps
1
350
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Transcript
そろそろGraphQLの話をしよう 2018/12/20 Mix Leap Study #30 Webフロントエンド 平成最後の冬の陣 @tatsushitoji
Hello mix Leap ! • 田路 竜士 @tatsushitoji • 社内スタートアップおじさん
• Frontend Engineer • Functional Programming
GraphQLとは?
GraphQLとは? • FacebookによるOSSで、2015年に発表 • 柔軟にデータを取得できるように設計されたAPI用のクエリ言語 • データの形式のみの定義のため言語やデータI/Oの方法に依存しない
GraphQLとは? • FacebookによるOSSで、2015年に発表 • 柔軟にデータを取得できるように設計されたAPI用のクエリ言語 • データの形式のみの定義のため言語やデータI/Oの方法に依存しない 手っ取り早く試すならGitHub GraphQLAPI v4
Rest API + Redux user post DB API DB
GraphQL + Apollo DB API DB GraphQLサーバ
• リクエストエンドポイントの選択 • リクエストの組み立て(パラメータ、ヘッダなど) • 状態管理 フロントエンドで持っていた ロジック
• リクエストエンドポイントの選択 • リクエストの組み立て(パラメータ、ヘッダなど) • 状態管理 フロントエンドで持っていた ロジック GraphQL +
Apollo(Client) で吸収できる
Apollo
Apollo Engine • 実行状況を監視したり、エラートラッキング、キャッシュの利 用状況の監視などを行うツールとクラウドサービス Apollo Server • GraphQLサーバを構築できるライブラリ Apollo
Client • フロントエンドでGraphQLをシンプルに扱うためのライブラリ Apollo CLI • 開発時に $ apollo *** でいろいろできるツール
Apollo Client supports …
ベーシックワークフロー 1. スキーマ定義 2. モックサーバ実装 3. フロントエンド実装
スキーマ定義 type Todo { id: ID! title: String! completed: Boolean!
createdAt: String! } type Query { todo(id: ID!): Todo! todos: [Todo!] } input CreateTodoInput { id: ID! title: String! completed: Boolean! createdAt: String! }
モックサーバ実装 • resolvers がサーバとしての実装の本体 • GetTodo の場合、 type Todo を満たす値もしくは
Promise<Todo> を返却すれば良い • $ node server.js で対話型のプレイグラウンドでクエリ を実行できる
フロントエンド実装 • create react app —typescript で type safe な環境
• Apollo client • 一応 lint や code formatter も
所感
Apollo Server の mock 便利 const server = new ApolloServer({
typeDefs: fs .readFileSync(path.join(!__dirname, "!../schema.graphql")) .toString(), mocks: true, !// resolvers: resolvers, }); ↑スキーマ定義をしておけば、定義した型で適当な値を返してくれる
Function as child Components <Query query={GET_TODOS} fetchPolicy="cache-and-network"> {({ data, loading,
error }) !=> { if (error !|| loading) { return <p>{error ? `Error! ${error}` : 'loading!!...'}!</p>; } if (data) { return data.todos.map((todo: any, index: number) !=> ( <List>{todo.title}!</List> )); } }} !</Query> ↑を実現するためにReduxでのaction, reducer, connect相当を内部でやってくれている
Code generator !/* tslint:disable !*/ !// This file was automatically
generated and should not be edited. !// ==================================================== !// GraphQL query operation: GetTodos !// ==================================================== export interface GetTodos_todos { id: string; title: string; completed: boolean; createdAt: string; } ↑schemaとGraphQLサーバから型を生成してくれる
Function as child Components <Query<GetTodos, {}> query={GET_TODOS} fetchPolicy="cache-and- network"> {({
data, loading, error }) !=> { if (error !|| loading) { return <p>{error ? `Error! ${error}` : 'loading!!...'}!</p>; } if (data !&& data.todos) { return data.todos.map((todo: any, index: number) !=> ( <List key={index}>{todo.title}!</List> )); } }} !</Query> ↑生成された型をGenericsで渡すだけでchildのfunctionの引数まで型推論が効く
年末年始はGraphQL どうですか?