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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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.5k
Other Decks in Technology
See All in Technology
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
540
【セミナー資料】Claude Code をセキュアに使うための考え方と設定の勘どころ / Claude Code Webinar 20260616
masahirokawahara
2
420
アジャイルな経理と Claude Code と経営の未来
kawaguti
PRO
3
160
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
160
2026 TECHFRESH 畢業分享會 - AI-Native 重塑軟體工程與虛擬講師
line_developers_tw
PRO
0
1.3k
LayerXにおけるセキュリティ管理の現在地と次の一手
tosho
0
250
Agent Skills設計で柔軟性と硬さのバランスが難しい話
nassy20
0
140
AWS Security Agent といっしょに脅威モデリングをやってみよう
amarelo_n24
1
180
【Snowflake Summit 2026 Recap!!】Snowflake Summit Deep Dive: Security & Governance
civitaspo
1
270
[チョークトーク資料]AWS DevOps Agent を使いこなす / AWS Dev Ops Agent Chalk Talk AWS Summit Japan 2026
kinunori
3
570
データサイエンスを価値につなげるプロジェクト設計 〜 DS一年目が現場で得た気づき 〜
ysd113
1
280
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
1.3k
Featured
See All Featured
Google's AI Overviews - The New Search
badams
0
1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
The Invisible Side of Design
smashingmag
302
52k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Tell your own story through comics
letsgokoyo
1
960
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Test your architecture with Archunit
thirion
1
2.3k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Done Done
chrislema
186
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
First, design no harm
axbom
PRO
2
1.2k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
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