Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Webシステム開発事例 と GraphQL Server with Laravel

@
November 30, 2019
42

Webシステム開発事例 と GraphQL Server with Laravel

@

November 30, 2019
Tweet

Transcript

  1. wget https://github.com/laradock/laradock/archive/v8.0.zip unzip v8.0.zip mv laradock-8.0 laradock cp laradock/env-example laradock/.env

    sed -i -e 's/^\(APP_CODE_PATH_HOST=\).*$/\1..\/laravel/' laradock/.env sed -i -e 's/^\(DATA_PATH_HOST=\).*$/\1..\/data/' laradock/.env sed -i -e 's/^\(COMPOSE_PROJECT_NAME=\).*$/\1laradock_techplay20191130/' laradock/.env sed -i -e 's/^\(MYSQL_VERSION=\).*$/\15.7/' laradock/.env wget https://github.com/laravel/laravel/archive/v6.5.2.zip unzip v6.5.2.zip mv laravel-6.5.2 laravel cp laravel/.env.example laravel/.env sed -i -e 's/^\(DB_HOST=\).*$/\1mysql/' laravel/.env sed -i -e 's/^\(DB_DATABASE=\).*$/\1default/' laravel/.env sed -i -e 's/^\(DB_USERNAME=\).*$/\1default/' laravel/.env sed -i -e 's/^\(DB_PASSWORD=\).*$/\1secret/' laravel/.env (cd laradock; docker-compose up nginx mysql workspace) & (cd laradock; docker-compose exec --user=laradock workspace bash)
  2. composer install php artisan key:generate composer require laravel/ui --dev php

    artisan ui -n vue --auth php artisan migrate npm install && npm run dev
  3. composer require nuwave/lighthouse php artisan vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider" --tag=schema php artisan

    vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider" --tag=config sed -i -e 's/\('\''middleware'\''.*\)/\1\n \\Illuminate\\Session\\Middleware\\StartSession::class,/' config/lighthouse.php sed -i -e 's/\('\''middleware'\''.*\)/\1\n \\Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse::class,/' config/lighthouse.php sed -i -e 's/\('\''middleware'\''.*\)/\1\n \\App\\Http\\Middleware\\EncryptCookies::class,/' config/lighthouse.php composer require mll-lab/laravel-graphql-playground
  4. cat << 'EOF' > database/migrations/2019_11_30_000000_create_posts_table.php <?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint;

    use Illuminate\Support\Facades\Schema; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('posts', function (Blueprint $table) { $table->bigIncrements('id'); $table->text('title'); $table->text('contents'); $table->unsignedBigInteger('user_id')->nullable(); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users')->onDelete('set null'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('posts'); } } EOF
  5. cat << 'EOF' > app/Post.php <?php namespace App; use Illuminate\Database\Eloquent\Model;

    use Illuminate\Database\Eloquent\Relations\BelongsTo; class Post extends Model { protected $fillable = ['title', 'contents', 'user_id']; public function user(): BelongsTo { return $this->belongsTo(User::class); } } EOF
  6. cat << 'EOF' >> graphql/schema.graphql type Mutation extend type Query

    { posts: [Post!]! @paginate(defaultCount: 10) post(id: ID @eq): Post @find } type Post { id: ID! title: String! contents: String! created_at: DateTime! updated_at: DateTime! user: User @belongsTo } extend type Mutation { createPost( title: String! contents: String! ): Post @create @inject(context: "user.id", name: "user_id") } EOF
  7. open http://localhost/graphql-playground # setting # "request.credentials": "same-origin" # mutation {

    createPost(title: "bar" contents: "baz") { id } } # query { posts { data { id title contents created_at updated_at user { id name } } } }