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
LaravelでGraphQLを試してみた
Search
2bo
January 18, 2020
Technology
570
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
Patterns in AI Driven Software Development
akosma
PRO
0
420
キヨさん、67歳。AIコーディングエージェントに挑む
happysamurai294
0
130
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
280
基本から分かる!AWSセキュリティ運用の考え方と任せ方
cmusudakeisuke
1
330
Claude Codeから見る、エンジニアの世界の変容とその先
oikon48
8
5.1k
reInvent2026stby LT00 "Change your life!"
shinichirokawano
1
510
AIに任せられるFlutterコードベースを作る 〜仕様をコードで表し、ハーネスで守る〜
myohei
1
600
Adversary Infrastructure Hunting101
disconinja
0
190
Maestro MCPとClaude Code Skillsによる自律的なE2Eテスト支援
asmz
0
390
AI時代の開発はウォーターフォールに回帰する? / development-with-ai-back-to-wf
okamototakuyasr2
0
170
今から始めるAWS環境の暗号移行 - ポスト量子時代に備える
sato4mi
0
140
クラウドエージェントの先駆け Devin。今も最先端を走る、他との違い
kinopeee
1
530
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
273
28k
First, design no harm
axbom
PRO
2
1.4k
Optimizing for Happiness
mojombo
378
71k
We Have a Design System, Now What?
morganepeng
55
8.4k
The Curse of the Amulet
leimatthew05
3
16k
Mobile First: as difficult as doing things right
swwweet
225
10k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Code Reviewing Like a Champion
maltzj
529
40k
The browser strikes back
jonoalderson
0
1.9k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
310
A Tale of Four Properties
chriscoyier
163
24k
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