A Laravel GraphQL server demo repo for https://modernjsforphpdevs.com/laravel-graphql-server/
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
bootstrap
config
database
laradock @ 0c41fce
public
resources
routes
storage
tests
.env.example
.gitattributes
.gitignore
.gitmodules
README.md
artisan
composer.json
composer.lock
package.json
phpunit.xml
server.php
webpack.mix.js
yarn.lock

README.md

laravel-graphql-server

This is a Laravel example repo for adding a GraphQL endpoint to your existing Laravel app, developed for https://www.modernjsforphpdevs.com/

Requirements

Installation

Clone with submodules

$ git clone --recursive git@github.com:zorfling/laravel-graphql-server.git

Use docker to spin up nginx, mysql and the workspace image.

$ cd laradock
$ cp env-example .env
$ docker-compose up -d nginx mysql workspace

Enter the workspace image to run commands

$ docker-compose exec workspace bash

Install the composer dependencies:

root@a99b46dd3004:/var/www# composer install

Then install the node dependencies:

root@a99b46dd3004:/var/www# yarn

# OR

root@a99b46dd3004:/var/www# npm install

Usage

Initialise Laravel

# in the workspace image
root@a99b46dd3004:/var/www# cp .env.sample .env
root@a99b46dd3004:/var/www# ./artisan key:generate

Run migrations and seed data

# in the workspace image
root@a99b46dd3004:/var/www# ./artisan migrate
root@a99b46dd3004:/var/www# ./artisan db:seed

Navigate to http://localhost/graphiql to see the GraphiQL explorer.

Try out some queries:

Get the username, first name and last name of all users, as well as their friends' usernames.

{
  allPeople {
    username
    first_name
    last_name
    friends {
      username
    }
  }
}

Get the username of user id 1, along with the username, first name, last name and email of all his friends.

{
  person (id: 1) {
    username
    friends {
      username
      first_name
      last_name
      email
    }
  }
}