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
そろそろGraphQLの話をしよう
Search
tt
December 20, 2018
Programming
320
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
110
Our favorite Dependency updates has been deprived
tatsushitoji
2
540
try Undux but...
tatsushitoji
0
290
Other Decks in Programming
See All in Programming
プロポーザルを書いてもらう
pvcresin
0
550
運用ダッシュボードの設計を誰も教えてくれないのだけどみなさんどうしてるんですか? - チームに監視するという文化を根付かせるための第一歩を踏みたい -
satoshi256kbyte
1
130
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.8k
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
340
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
510
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
150
SlackアプリとLambdaの 連携を構築した話
pawn_4_s
1
120
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
今さら聞けない .NET CLI
htkym
0
200
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
630
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
520
Foundation Models frameworkで画像分析
ryodeveloper
1
620
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
500
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
280
GraphQLとの向き合い方2022年版
quramy
50
15k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
470
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
We Are The Robots
honzajavorek
0
300
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
250
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
490
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 どうですか?