Hi, my name is Andrés Felipe, on this post we are make a server graphql with laravel.
Requisites
- Php v8
- Composer v2
Craft Laravel app
To create a laravel proyect run this commando in console
composer create-project laravel/laravel graphql-server
Install Graphql libraries
Inside in our proyect laravel run the following command
composer require nuwave/lighthouse
This command will install the graphql for laravel and php.
Mext step run the following command:
php artisan vendor:publish --tag=lighthouse-config
to publish the config the graphql in
config/lighthouse.php
and add the graphql uri to cors in
config/cors.php
'paths' => ['api/*', 'graphql', 'sanctum/csrf-cookie'],
Next step publish the default schema where you add the code for graphql.
Install Graphql Playground
The playground is a enviroment for develop stage for test your queries or mutation below the pass a code in your front whit apollo.
For install this playground run de follow command
composer require mll-lab/laravel-graphql-playground
When the installation is finished it will be published the route
/graphql-playground
and publish the config with
php artisan vendor:publish --tag=graphql-playground-config
this will public the config the playground in
config/graphql-playground.php
The url for consume the api is
/graphql
In this moment we have:
- The libraries for laravel the graphql.
- The playground for test our api graphql.
it would look something like this
Finish
In other post, we a create a api whit
- Users
- Posts
when one user have many posts like a social network
This is my firsts post, i hope this help you and i would aprreciatte if you comment,rate and follow me
TANKS.
Top comments (0)