1
1

More than 1 year has passed since last update.

【2023年版】Laravel + Lighthouse チュートリアル環境構築 ( macOS + DockerCompose )

Last updated at Posted at 2023-08-18

実行環境

OS macOS Monterey 13.5
shell zsh 5.8.1 (x86_64-apple-darwin21.0)
middleware Docker(24.0.2, build cb74dfc)
Docker compose(v2.18.1)

本記事で得られる結果

  • Laravel Project
    • Lighthouse導入済み

参考資料

事前準備

  1. PHPがインストール済みであること

  1. Docker Desktopがインストール済みであること

手順

  1. Laravelのベースプロジェクトの作成

    curl -s "https://laravel.build/example-app" | bash
    

    “example-app”は任意のプロジェクト名に変更可能

  2. Docker上で起動する

    cd example-app
    ./vendor/bin/sail up
    
  3. 起動したコンテナへアクセス

    docker compose exec laravel.test bash
    
  4. マイグレーションの実行

    php artisan migrate
    
  5. テストデータの作成

    php artisan tinker
    \App\Models\User::factory(10)->create()
    

    作業後はexitで終了する

  6. Lighthouseのインストール

    composer require nuwave/lighthouse
    
  7. デフォルトスキーマの作成

    php artisan vendor:publish --tag=lighthouse-schema
    
  8. プラグインのインストール

    composer require mll-lab/laravel-graphiql
    
  9. http://localhost/graphiql へアクセスし、データが取得できるか確認する

    {
      user(id: 1) {
        id
        name
        email
      }
    }
    
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1