Lighthouse Tutorial
A basic starter pack for a GraphQL API using Lighthouse and Laravel
It's very simple to get the API up and running. First, create the database (and database user if necessary) and add them to the .env file.
DB_DATABASE=your_db_name
DB_USERNAME=your_db_user
DB_PASSWORD=your_passwordThen install, migrate, seed, and run the server:
composer install
php artisan migrate
php artisan serveVisit http://127.0.0.1:8000/graphql-playground on your browser to test the API
Alternatively you can use Postman or Insomnia
Use this url: http://localhost:8000/graphql
First run
php artisan tinkerThen on the shell that opens up run
factory('App\User',10)->create();
factory('App\Post',50)->create();
factory('App\Comment',50)->create();or simply
composer seed{
  user(id: 1) {
    id
    name
    email
  }
}
{
  users(count:10) {
    paginatorInfo {
      total
      hasMorePages
      currentPage
      lastPage
      perPage
      firstItem
      lastItem
      count
    }
    data {
      id
      name
      email
    }
  }
}
{
  post(id: 1) {
    id
    title
    content
    user {
      id
      name
    }
    comments {
      id
      reply
    }
  }
}
{
  posts {
    id
    title
    user {
      id
      name
    }
    comments {
      id
      reply
    }
  }
}
mutation {
  createUser(
    name: "Ryan Wire"
    email: "simiyuwire@gmail.com"
    password: "1234567"
  ){
    id,
    name
  }
}
mutation {
    login(data: {
        username: "oberbrunner.reginald@example.net",
        password: "password"
    }) {
        access_token
    }
}