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
入門Hasura
Search
ryo
December 05, 2019
Technology
2.9k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
入門Hasura
もくテク #4 冬のLT大会
ryo
December 05, 2019
More Decks by ryo
See All by ryo
Bridging Social Graphs
kawamataryo
0
380
Raycast AI APIを使ってちょっと便利なAI拡張機能を作ってみた
kawamataryo
1
610
退屈なことはDevinにやらせよう〜〜Devin APIを使ったVisual Regression Testの自動追加〜
kawamataryo
5
2.4k
SaaS公式MCPサーバーをリリースして得た学び
kawamataryo
7
2.2k
Raycast AI APIを使ってちょっと便利な拡張機能を作ってみた / created-a-handy-extension-using-the-raycast-ai-api
kawamataryo
1
920
ts-morphのパフォーマンス改善Tips
kawamataryo
0
150
webpack to Rspack
kawamataryo
0
140
GitHub Actions と Datadog でコードベースの定点観測
kawamataryo
7
2.2k
個人開発駆動学習 / personal development driven learning
kawamataryo
1
320
Other Decks in Technology
See All in Technology
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
130
AI駆動開発、viviONの1年 ── うまくいったこと・いかなかったこと
vivion
0
250
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
280
大阪オフィスに Unitree Go2 がやってきたので Physical AI やってみた
dafujii
0
310
[2026 Oracle Technical Deep Dive] AI時代のデータベース基盤をどう選ぶ? Exadata Database Serviceの選択肢と使い分け (2026年9月17日開催)
oracle4engineer
PRO
0
220
Databricksメトリクスビューはじめてのもくもく会
taka_aki
0
200
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
450
HolmesGPTで始めるSREエージェント入門!プラットフォームの障害調査はAIにお任せ 〜
leveragestech
PRO
0
150
Codex概要
ymiya55
0
400
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
230
雪かき部 #7 もう怖くない!SELECT文!
foursue
0
280
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
210
Featured
See All Featured
Statistics for Hackers
jakevdp
799
230k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
550
A Tale of Four Properties
chriscoyier
163
24k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
840
Chasing Engaging Ingredients in Design
codingconduct
0
340
What's in a price? How to price your products and services
michaelherold
247
13k
Between Models and Reality
mayunak
4
480
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Side Projects
sachag
456
43k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Transcript
入門 Hasura 〜 HasuraでサクッとGraphQL 体験 〜 @RyoKawamata
自己紹介
@RyoKawamata 消防士歴 6年半, エンジニア歴 1年半 株式会社Misoca リモートワーク@茨城
今日話すこと
GraphQLの簡単な紹介 Hasuraで出来ること・出来ないこと
GraphQL とは何か?
API向けの問い合わせ言語・仕様
問い合わせ言語?
APIを対象にしたSQL的なもの
あるユーザーの 名前、会社名、URLを取得したい example
SELECT name, company, url FROM users WHERE id = '1234'
SQL DB
SQL DB name compony url ryo misoca misoca.jp
query getUser { user(id: ‘1234’) { name company url }
} GraphQL API Server
“data” { ”user” { “name”: “ryo” “company”: “misoca” “url”: “misoca.jp”
} } GraphQL API Server
• 必要なものを必要な分だけ取得できる • 単一のエンドポイント • 強力な型システムを持つ feature
REST API の課題とGraphQL
過剰な取得 必要のないデータまで まとめて取得してしまう
example ユーザーの名前とリポジトリ数を取得したい
REST Request GET https://api.github.com/users/${ username }
REST Response { "login": "kawamataryo", "id": 11070996, "node_id": "MDQ6VXNlcjExMDcwOTk2", "avatar_url":
"https://avatars1.githubusercontent.com/u/11070996?v=4", "gravatar_id": "", "public_repos": 95, "public_gists": 0, "followers": 8, "following": 7, "url": "https://api.github.com/users/kawamataryo", "html_url": "https://github.com/kawamataryo", "followers_url": "https://api.github.com/users/kawamataryo/followers", "following_url": "https://api.github.com/users/kawamataryo/following{/other_user}", "gists_url": "https://api.github.com/users/kawamataryo/gists{/gist_id}", . . 以下略
REST Response { "login": "kawamataryo", "id": 11070996, "node_id": "MDQ6VXNlcjExMDcwOTk2", "avatar_url":
"https://avatars1.githubusercontent.com/u/11070996?v=4", "gravatar_id": "", "public_repos": 95, "public_gists": 0, "followers": 8, "following": 7, "url": "https://api.github.com/users/kawamataryo", "html_url": "https://github.com/kawamataryo", "followers_url": "https://api.github.com/users/kawamataryo/followers", "following_url": "https://api.github.com/users/kawamataryo/following{/other_user}", "gists_url": "https://api.github.com/users/kawamataryo/gists{/gist_id}", . . 以下略 大量の不要なカラムも 取得してしまう
{ user(login: “username”) { name repositories { totalCount } }
} GraphQL Request POST https://api.github.com/graphql
{ "data": { "user": { "name": "ryo", "repositories": { "totalCount":
106 } } } } GraphQL Respose
{ "data": { "user": { "name": "ryo", "repositories": { "totalCount":
106 } } } } GraphQL Respose 必要なリソースのみ 宣言的に取得出来る
過小な取得 必要な情報によっては 複数回のリクエストを組み合わ せる必要がある。 (関連まで取りたい場合など)
example あるユーザーのフォロワー数と、 そのフォロワーのフォロワー数を取得したい
REST GET https://api.github.com/users/${ username }/followers でフォロワーを取得 さらにフォロワーの数だけ、同じリクエストを投げ て、全ての結果をカウントする。
REST GET https://api.github.com/users/${ username }/followers でフォロワーを取得 さらにフォロワーの数だけ、同じリクエストを投げ て、全ての結果をカウントする。 複数回のリクエストの 統合が必要
{ user(login: “username”) { followers { totalCount nodes { name
followers { totalCount } } } } } GraphQL Request
{ user(login: “username”) { followers { totalCount nodes { name
followers { totalCount } } } } } GraphQL Request 一つのリクエストで 関連のデータまでまとめて 取得出来る
つまり
GraphQL 最高便利..!!!
でも..
サーバーサイドの実装大変そう、、 自由に取れるってセキュリティ大丈夫?? そもそもAPI変えるほどの工数ない
大丈夫!!!
Hasura がある!!
Hasuraとは?
PostgreSQLのTableスキーマから GraphQLのAPIを自動生成するもの
None
DEMO
Hasuraの良いところ
CRUD・Subscription のクエリを自動で提供してくれる Pross
• ネストした関連データの取得 • 集計処理(count, sum, avg, max, min) • フィルター処理(eql,
pattern match) • 並び替え • ページネーション • トランザクションでの更新 • カスタムSQL関数を含むクエリ ...etc
テーブルのカラム単位で 操作の認可を設定できる Pross
None
Firebase, Auth0
Event Trigger・Remote Schema で柔軟なAPIも構築可能 Pross
Event Trigger 指定されたテーブルのイベントをトリガーに Webhookを呼び出してカスタムロジックを実行する機能
Remote Schema 独自に実装した GraphQLサーバーを Hasuraのエンドポイ ントにマージして利用 可能にする機能
Hasuraを使う上での注意
クエリに対するValidationが まぁまぁきつい Cons
PostgreSQLのTriggerで実行 or 別にGraphQL サーバーを立てて Remote Schema実行
まとめ
Hasuraは便利なものの 全てを解決すことはできない。 ただ、他サービスと上手く連携し作り上げられ れば、GraphQL APIサーバー構築の工数を大 幅に下げられる可能性はある
参考
O`REILLY 初めてのGraphQL ~ WEBサービスを作って学ぶ次世代API~ 定価 2,860 円