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
大型犬好きによるPugの紹介
yamanoku
1
110
AIに攻撃される前に、AIに攻撃させる
tsuchikazu
0
170
Claude Code本は、どのように執筆チームで書かれたか
oikon48
1
360
パッチ更新でterraform initが落ちた日
grimoh
1
120
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
370
しろおびから始める!ログ活用の第一歩
shumei_ito
0
870
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
1
140
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
130
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.4k
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
1
780
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
830
AI駆動開発、viviONの1年 ── うまくいったこと・いかなかったこと
vivion
0
290
Featured
See All Featured
A Soul's Torment
seathinner
8
3.7k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
400
WCS-LA-2024
lcolladotor
0
870
How to Ace a Technical Interview
jacobian
280
24k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building Applications with DynamoDB
mza
96
7.2k
How GitHub (no longer) Works
holman
316
150k
Product Roadmaps are Hard
iamctodd
55
13k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
780
Scaling GitHub
holman
464
140k
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