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
340
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
そろそろGraphQLの話をしよう
GraphQL と Apollo のお話
tt
December 20, 2018
Transcript
22 slides
そろそろ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 どうですか?
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
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
340
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
260
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
130
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
200
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
350
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
320
SODA - FACT BOOK(JP)
sodainc
1
40k
protojson における文字化けの扱い
kazuki1023
0
420
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
0
180
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
310
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
230
複数ドメインを一つのアプリに統合するFlutterの設計と運用_FlutterKaigi2026登壇資料(須永高弘)
takahirosunaga
0
180
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
5
5.8M
A designer walks into a library…
pauljervisheath
211
25k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The Curse of the Amulet
leimatthew05
4
17k
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
590
BBQ
matthewcrist
90
10k
Raft: Consensus for Rubyists
vanstee
143
7.9k
GitHub's CSS Performance
jonrohan
1033
470k