Welcome to this straightforward project designed to demonstrate the practical use of GraphQL with Laravel. This project serves as a basic blog system featuring posts and categories.
GraphQL is a query language for APIs and an execution engine for fulfilling these queries using your existing data. It offers a comprehensive and intuitive way to describe the data available in your API, granting clients the ability to request exactly what they need, without any excess information. GraphQL simplifies the process of evolving APIs over time and provides powerful tools for developers.
Here's a concise comparison between GraphQL and REST:
- REST is an architectural style.
- REST is a protocol.
- REST is a collection of guidelines, rules, constraints, principles, and rules.
- GraphQL is a query language, not an architectural style or protocol.
The primary goals of this project are:
- To understand how to leverage GraphQL with Laravel.
- To become proficient in using the graphql-laravel package for GraphQL in Laravel.
This project utilizes the following technologies:
- Laravel v10.28
- PHP v8.2
- MySQL v8.0
- Docker v24.0.6
To achieve its functionality, this project incorporates several packages, including:
- GraphQL Laravel v9.1
- Laravel Media Library v10.13
- Laravel Sluggable v3.5
To execute this project, follow these steps:
- Clone the repository to your local machine.
- Generate a .env file by executing the following command:
cp .env.example .env
- Install the project dependencies using Docker and Composer:
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php82-composer:latest \
composer install --ignore-platform-reqs
- Initiate the containers with the following command:
./vendor/bin/sail up -d
- Generate an application key with:
./vendor/bin/sail artisan key:generate
- Execute the database migrations:
./vendor/bin/sail artisan migrate
- Populate the database with initial data:
./vendor/bin/sail artisan db:seed
- Create a symbolic link for storage:
./vendor/bin/sail artisan storage:link
Once the project is operational, follow these steps to make the most of it:
- Launch Postman or your preferred API testing tool.
- Create a new GraphQL request.
- Set the URL to http://your-domain/graphql (replace your-domain with your actual domain or local URL).
I value your input and welcome any suggestions or feedback you may have regarding this project. If you encounter any issues, have ideas for improvements, or wish to share your experience, please don't hesitate to reach out. Your feedback will help me enhance and refine this project further. For a comprehensive tutorial on building a GraphQL API using Laravel, you can refer to the article on FreeCodeCamp. Thank you for your collaboration!