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
入門Hasura
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
340
Raycast AI APIを使ってちょっと便利なAI拡張機能を作ってみた
kawamataryo
1
590
退屈なことはDevinにやらせよう〜〜Devin APIを使ったVisual Regression Testの自動追加〜
kawamataryo
5
2.3k
SaaS公式MCPサーバーをリリースして得た学び
kawamataryo
7
2.2k
Raycast AI APIを使ってちょっと便利な拡張機能を作ってみた / created-a-handy-extension-using-the-raycast-ai-api
kawamataryo
1
900
ts-morphのパフォーマンス改善Tips
kawamataryo
0
140
webpack to Rspack
kawamataryo
0
140
GitHub Actions と Datadog でコードベースの定点観測
kawamataryo
7
2.1k
個人開発駆動学習 / personal development driven learning
kawamataryo
1
320
Other Decks in Technology
See All in Technology
Bet AI Day 2026丨How We Bet AI: AIとともに働く場をつくる
layerx
PRO
1
2k
『止めない』を設計する — 制約の中で、事業の根幹を支える判断
hiroyaterui
0
120
Bet AI Day 2026丨Agentは、「金融」という巨大産業の何を変えられるのか
layerx
PRO
0
630
AIとペアプロを始める。人とのペアプロをやめる。ペアプロの良さを改めて知る。もっと好きになった。 / Rediscovering Pair Programming
honyanya
1
150
AI時代に、プロダクトの数だけ積み上がる所有コストをどうエンジニアリングするか / Engineering the Cost of Ownership
kzkmaeda
0
830
Nav2、Nav3 ... はたまた自作?〜 作って理解する Nav3 の設計意図 〜 / Nav2, Nav3 ... or Build Your Own? — Understanding Nav3's design intent by building it from scratch
yanzm
0
180
[RSJ26] AnoleVLA: Lightweight Vision-Language-Action Model with Deep State Space Models for Mobile Manipulation
keio_smilab
PRO
0
120
AIで実装は速くなった。なのにプロダクトは速くならない。職能の壁を越えて価値のフローを設計する
nwiizo
6
6.2k
少人数データチームのDevin活用実践事例
runandy16
2
420
V8コントリビュート超入門
riyaamemiya
0
130
魔法少女がClaude Codeを監視する / ccportal-deck
noriyukitakei
3
120
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
490
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Making Projects Easy
brettharned
120
6.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
The Limits of Empathy - UXLibs8
cassininazir
1
630
Mobile First: as difficult as doing things right
swwweet
225
10k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
510
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
A better future with KSS
kneath
240
18k
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 円