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
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
280
Raycast AI APIを使ってちょっと便利なAI拡張機能を作ってみた
kawamataryo
1
570
退屈なことは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
870
ts-morphのパフォーマンス改善Tips
kawamataryo
0
130
webpack to Rspack
kawamataryo
0
120
GitHub Actions と Datadog でコードベースの定点観測
kawamataryo
7
2.1k
個人開発駆動学習 / personal development driven learning
kawamataryo
1
310
Other Decks in Technology
See All in Technology
はじめてのWDM
miyukichi_ospf
1
140
Foxgloveについて 実際にExtensionを開発して公開するまでの話 / About Foxglove: The Story of Developing and Releasing an Extension
ry0_ka
0
220
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.4k
Empower GenAI with Agile - あなたのアジャイルが生成AIのバフになる仕組み
hageyahhoo
1
180
Making sense of Google’s agentic dev tools
glaforge
1
200
End-to-Endで考える信頼性 —LINEアプリにおけるクライアント開発×SRE連携の実践
maruloop
4
4.2k
Claude Code公式skillで 自分の仕事を少しずつ手放そう!(Claude Code開発ノウハウ大公開スペシャル by クラスメソッド)
kaym
1
330
ZOZOTOWNの進化と信頼性を両立する負荷試験
zozotech
PRO
2
160
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
1.1k
CDKで書くECSのベストプラクティス、 改めて考え直す2026 #cdkconf2026
makies
0
120
ポストモーテム! DDoSからサイトは守れた。 でもビジネスは守れなかった。
bengo4com
1
2.9k
SRE依存からの脱却 運用を開 発チームへ移す、 フルサイ クル開 発体制の実践
joooee0000
0
2.7k
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
230
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
The SEO identity crisis: Don't let AI make you average
varn
0
510
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
What's in a price? How to price your products and services
michaelherold
247
13k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
930
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
240
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
340
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
BBQ
matthewcrist
89
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 円