This is a Laravel example repo for adding a GraphQL endpoint to your existing Laravel app, developed for https://www.modernjsforphpdevs.com/
- PHP 7.1.3 or higher
- Node.js 6.0.0 or higher
- Docker
- and the usual Laravel application requirements.
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
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
}
}
}