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
LaravelでGraphQLを試してみた
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
2bo
January 18, 2020
Technology
560
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LaravelでGraphQLを試してみた
2bo
January 18, 2020
More Decks by 2bo
See All by 2bo
LaravelでDIを扱う仕組み ~Service ContainerとService Provider~
tsubokoh
2
1.6k
Other Decks in Technology
See All in Technology
SnowflakeCoCoでデータエンジニアリング!
foursue
0
170
データ組織の転換期 一足飛びしない段階的戦略
leveragestech
PRO
0
150
AIQAのナレッジ構築について
qatonchan
1
160
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
1.7k
ウォーターフォール開発案件のPMとしてAI活用を模索している話
hatahata021
3
310
LangfuseによるLLMOps基盤の構築と活用事例
zozotech
PRO
1
280
もう一度考える SRE チームの作り方・育て方 / Rethinking SRE #1: Building and Growing SRE Teams
rrreeeyyy
5
980
[しろおび夏祭り2026] チャットするAIから、作業するAIへ - 使われ方の変化と、その裏側で起きていること
kk0n
0
1.6k
OSPN.JPバージョンアップ作業進捗のご報告 / 20260801-osc26kyoto
akkiesoft
0
260
修正PRを食べてレビュースキルが賢くなる:Claude Codeによる自己改善サイクル
yuyaumetsu
4
1.1k
Data Hubグループ 紹介資料
sansan33
PRO
0
3.1k
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
230
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
660
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.2k
Building Adaptive Systems
keathley
44
3.2k
Thoughts on Productivity
jonyablonski
76
5.3k
エンジニアに許された特別な時間の終わり
watany
108
250k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Site-Speed That Sticks
csswizardry
13
1.4k
Speed Design
sergeychernyshev
33
2k
Into the Great Unknown - MozCon
thekraken
41
2.7k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Transcript
LaravelでGraphQL を試してみた
Hello! • @AkogareSe • エンジニア 7年目 • 最近「風が強く吹いている」を観る泣く • 今の開発チームは主にPHP
• Laravelを勉強中 ◦ 勉強会を開催/参加したい 2
What is GraphQL? • APIのクエリ言語 • 仕様であり製品ではない 3
特徴 • 型安全 • 必要な情報のみを取得可能 • レスポンスの形式が予測しやすい 4
• Laravel用GraphQLライブラリ 5 Lighthouse
Example 6
Database Table 7
8 Users • id • name Posts • id •
user_id • content 1 * Users and Posts
Laravel Model Class 9
namespace App; class User extends Model { public function posts():
HasMany { return $this->hasMany(Post::class); } } namespace App; class Post extends Model { public function user(): BelongsTo { return $this->belongsTo(User::class); } } app/User.php app/Post.php 10
GraphQLの スキーマ定義(SDL) 11
複数のPostを持つ User::posts(): HasManyと対応付け type User { id: ID! name: String!
posts: [Post!]! @hasMany } type Post { id: ID! content: String! user: User! @belongsTo } type Query { userById(id: Int! @eq): User @find } タイプ定義 Modelと自動で対応付け フィールド名と型( !はNOT NULL, [ ]は配列) 1人のユーザに所属する Post::user(): BelongsToと対応付け 特別なタイプ データ取得クエリを定義 graphql/schema.graphql idに一致した1ユーザ分の情報を返す 12
API Access 13
14 Request Respons
15 Request Respons
まとめ 16
• GraphQLはAPIの仕様 • LighthouseでGraphQLを実装できる 17
Thanks! Sample Project https://github.com/2bo/laravel-graphql-sample 18
References ◎ GraphQL ◎ Lighthouse ◎ GraphQL入門 - 使いたくなるGraphQL ◎
「GraphQL」徹底入門 ─ RESTとの比較、API・フロント双方の実装から 学ぶ ◎ LaravelにLighthouseを導入してGraphQLサーバーを作る ◎ [Laravel] Fakerで日本語を扱う ◎ Laravel Lighthouse GraphQL - Sorting on server side 19
1. Laravelのプロジェクトを作る 1.1. $ laravel new lighthouse-sample 2. マイグレートする(デフォルトでUsersテーブルが作成される) 2.1.
$ php artisan migrate 3. lighthouseとlaravel-graphql-playgroundを追加する 3.1. $ composer require nuwave/lighthouse 3.2. $ composer require mll-lab/laravel-graphql-playground 4. graphql/schema.graphqlを生成する 4.1. $ php artisan vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider" --tag=schema 5. http://[hostname]/graphql-playgroundをブラウザで開く おまけ~Lighthouseを試す際の導入手順~ 20