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
2bo
January 18, 2020
Technology
550
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.5k
Other Decks in Technology
See All in Technology
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
510
AIにフローを作らせようとして挫折した話
hamatsutaichi
0
200
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.8k
SIer20年! 培ったスキルがスタートアップで輝く時
shucho0103
0
370
OCI Oracle AI Database Services新機能アップデート(2026/03-2026/05)
oracle4engineer
PRO
0
220
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
8
5.8k
Cloud Run のアップデート 触ってみる&紹介
gre212
0
310
ルールやカスタム機能、どう使う?理想の出力を引き出すために今知りたいIBM Bob 5つの機能
muehara
1
340
LLMを「主役」にしないための 3つの原則
techtekt
PRO
0
120
AIプラットフォームを運用し続けるための可観測性
tanimuyk
4
1.1k
価格.comをAI駆動で全面刷新する ー 30年分の技術的負債を返し、次の30年の土台をつくる ー / AI Engineering Summit Tokyo 2026
tkyowa
49
52k
Chart.js が簡単に使えるようになっていたので OGP 画像生成に使った話
kamekyame
0
160
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
The SEO Collaboration Effect
kristinabergwall1
1
480
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
720
Six Lessons from altMBA
skipperchong
29
4.3k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
KATA
mclloyd
PRO
35
15k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
The Curious Case for Waylosing
cassininazir
1
370
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
240
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
240
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
130
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