Skip to content

KwanJunEr/php_graphql_learn_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Set up Laravel and GraphQL


Refer to this document: https://lighthouse-php.com/

Setup as the following according to the lighthouse documentation


Step 1

Option 1

 
  composer create-project laravel/laravel graphql-api
  cd graphql-api
 

Option 2


 laravel new laravel-graph

Step 2:Install Lighthouse

Install Lighthouse via Composer:


 composer require nuwave/lighthouse

Step3:Publish the Lighthouse Configuration

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

After that, you’ll have:

  • config/lighthouse.php
  • graphql/schema.graphql

Configure GraphQL Route

By default, Lighthouse automatically registers /graphql as the endpoint. You can check or change it in config/lighthouse.php:

 
  'route' => [
    'uri' => '/graphql',
],
 

Extra Stuff


 php artisan about 

How Laravel Lighthouse GraphQL Works Behind the Scenes

  1. The query goes to /graphql
  2. Lighthouse parses your query
  3. Lighthouse sees two fields: ads and posts
  4. It checks schema: ads → AdsQuery@all and posts → PostsQuery@all
  5. It calls both resolvers: - App\GraphQL\Queries\AdsQuery::all() - App\GraphQL\Queries\PostsQuery::all()
  6. Each resolver fetches data (Eloquent, controller, repository, etc.)
  7. Lighthouse merges both results into one JSON response

How to Add in GraphQL into modules

Doument Link: https://docs.google.com/document/d/1eks0pFBePMDVdYc3KUz96izT_8e4CVs3l_Q-EIDuL1M/edit?usp=sharing

About

Refer to Lighthouse for PHP (Laravel) and GraphQL Integration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages