Phonexay Singharatsavong

Phonexay Singharatsavong

Who am I?

I have been programming for over 20 years and wanted to start a blog about things I have learned over the years, am still learning, and will be learning, feel free to contact me.


What I write about


Recent Posts

Lighthouse - GraphQL with Laravel

Recently I been investigating using GraphQL over using REST. I have been using Laravel as my backend php server to serve JSON. It's pretty easy to setup and Laravel is great as a web framework. I decided to explore using GraphQL and found out there is something called Lighthouse that works with Laravel. This won't go through Laravel or GraphQL in depth, because each of those alone is very in depth, I'll just go through the basic setup of Lighthouse with Laravel which was pretty easy to setup.

Starting off for the project, I ran these two commands from the command line(run this in your laravel project directory):

composer require nuwave/lighthouse
composer require mll-lab/laravel-graphql-playground

This will setup GraphQL in Laravel and install the IDE for GraphQL.

Screen Shot 2020-09-27 at 1.30.47 PM.png

Next make sure you have a schema setup with your databse and run this, I had a few tables:

php artisan vendor:publish --tag=lighthouse-schema

This will publish the lighthouse schema and you can start testing it by using, if you have a user table you can send a query to it:

-yourdomain-/graphql-playground

Query:

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

This is the basic setup and I'm still exploring GraphQL, I'll be updating this blog as I discover more about GraphQL.